Simplify throttling code

Change-Id: I54ebdf0bc61d5628d1755b75232a934358b112ff
This commit is contained in:
Daimona Eaytoy 2020-01-07 17:52:16 +01:00
parent 539df33889
commit c54e2fc180

View file

@ -794,31 +794,18 @@ class AbuseFilterRunner {
protected function isThrottled( $throttleId, $types, $rateCount, $ratePeriod, $global = false ) {
$stash = MediaWikiServices::getInstance()->getMainObjectStash();
$key = $this->throttleKey( $throttleId, $types, $global );
$count = intval( $stash->get( $key ) );
$count = (int)$stash->get( $key );
$logger = LoggerFactory::getInstance( 'AbuseFilter' );
$logger->debug( "Got value $count for throttle key $key" );
if ( $count > 0 ) {
$stash->incr( $key );
$count++;
$logger->debug( "Incremented throttle key $key" );
} else {
$logger->debug( "Added throttle key $key with value 1" );
$stash->add( $key, 1, $ratePeriod );
$count = 1;
}
$count = $stash->incrWithInit( $key, $ratePeriod );
if ( $count > $rateCount ) {
$logger->debug( "Throttle $key hit value $count -- maximum is $rateCount." );
// THROTTLED
return true;
}
$logger->debug( "Throttle $key not hit!" );
// NOT THROTTLED
return false;
}