diff --git a/includes/AbuseFilter.php b/includes/AbuseFilter.php index 009746dfa..0808d77e5 100644 --- a/includes/AbuseFilter.php +++ b/includes/AbuseFilter.php @@ -594,15 +594,11 @@ class AbuseFilter { return [ 0, 0, 0, 0 ]; } - // 1000 ms in a sec - $timeProfile = ( $curTotalTime / $curCount ) * 1000; - // Return in ms, rounded to 2dp - $timeProfile = round( $timeProfile, 2 ); + // Return in milliseconds, rounded to 2dp + $avgTime = round( $curTotalTime / $curCount, 2 ); + $avgCond = round( $curTotalConds / $curCount, 1 ); - $condProfile = ( $curTotalConds / $curCount ); - $condProfile = round( $condProfile, 0 ); - - return [ $curCount, $profile['matches'], $timeProfile, $condProfile ]; + return [ $curCount, $profile['matches'], $avgTime, $avgCond ]; } /** @@ -1014,7 +1010,7 @@ class AbuseFilter { */ public static function filterProfileKey( $filter ) { $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); - return $cache->makeKey( 'abusefilter-profile', 'v2', $filter ); + return $cache->makeKey( 'abusefilter-profile', 'v3', $filter ); } /** diff --git a/includes/AbuseFilterRunner.php b/includes/AbuseFilterRunner.php index 09892cb96..a0d56f1bb 100644 --- a/includes/AbuseFilterRunner.php +++ b/includes/AbuseFilterRunner.php @@ -375,7 +375,7 @@ class AbuseFilterRunner { $pattern = trim( $row->af_pattern ); $result = AbuseFilter::checkConditions( $pattern, $this->parser, true, $filterName ); - $timeTaken = microtime( true ) - $startTime; + $timeTaken = 1000 * ( microtime( true ) - $startTime ); $condsUsed = $this->parser->getCondCount() - $startConds; $this->profilingData[$filterName] = [ @@ -403,9 +403,8 @@ class AbuseFilterRunner { $this->recordProfilingResult( $filterID, $params['time'], $params['conds'], $params['result'] ); } - $runtime = $params['time'] * 1000; - if ( $runtime > $wgAbuseFilterSlowFilterRuntimeLimit ) { - $this->recordSlowFilter( $filterName, $runtime, $params['conds'], $params['result'] ); + if ( $params['time'] > $wgAbuseFilterSlowFilterRuntimeLimit ) { + $this->recordSlowFilter( $filterName, $params['time'], $params['conds'], $params['result'] ); } } } @@ -414,7 +413,7 @@ class AbuseFilterRunner { * Record per-filter profiling data * * @param int $filter - * @param float $time + * @param float $time Time taken, in milliseconds * @param int $conds * @param bool $matched */ diff --git a/tests/phpunit/AbuseFilterConsequencesTest.php b/tests/phpunit/AbuseFilterConsequencesTest.php index 3355526ad..05a595489 100644 --- a/tests/phpunit/AbuseFilterConsequencesTest.php +++ b/tests/phpunit/AbuseFilterConsequencesTest.php @@ -1832,7 +1832,7 @@ class AbuseFilterConsequencesTest extends MediaWikiTestCase { 17 => [ 'matches' => 1, 'actions' => 6, - 'averageConditions' => 4.0 + 'averageConditions' => 4.3 ], 19 => [ 'matches' => 1, @@ -1872,7 +1872,7 @@ class AbuseFilterConsequencesTest extends MediaWikiTestCase { 17 => [ 'matches' => 1, 'actions' => 6, - 'averageConditions' => 4.0 + 'averageConditions' => 4.3 ], 19 => [ 'matches' => 1, @@ -1912,7 +1912,7 @@ class AbuseFilterConsequencesTest extends MediaWikiTestCase { 17 => [ 'matches' => 1, 'actions' => 6, - 'averageConditions' => 4.0 + 'averageConditions' => 4.3 ], 19 => [ 'matches' => 1,