Merge "Simplify throttling code"

This commit is contained in:
jenkins-bot 2020-01-22 17:19:52 +00:00 committed by Gerrit Code Review
commit 5db1032618

View file

@ -804,31 +804,18 @@ class AbuseFilterRunner {
) {
$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;
}