mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-24 06:03:49 +00:00
Simplify throttling code
Change-Id: I54ebdf0bc61d5628d1755b75232a934358b112ff
This commit is contained in:
parent
539df33889
commit
c54e2fc180
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue