diff --git a/includes/FilterProfiler.php b/includes/FilterProfiler.php index aaeb6e983..c1ed93daf 100644 --- a/includes/FilterProfiler.php +++ b/includes/FilterProfiler.php @@ -3,7 +3,6 @@ namespace MediaWiki\Extension\AbuseFilter; use BagOStuff; -use DeferredUpdates; use IBufferingStatsdDataFactory; use MediaWiki\Config\ServiceOptions; use Psr\Log\LoggerInterface; @@ -242,35 +241,32 @@ class FilterProfiler { * @phan-param array $data */ public function recordPerFilterProfiling( Title $title, array $data ) : void { - // Defer profiling updates to avoid massive (~1 second) edit time increases - DeferredUpdates::addCallableUpdate( function () use ( $title, $data ) { - $slowFilterThreshold = $this->options->get( 'AbuseFilterSlowFilterRuntimeLimit' ); + $slowFilterThreshold = $this->options->get( 'AbuseFilterSlowFilterRuntimeLimit' ); - foreach ( $data as $filterName => $params ) { - list( $filterID, $global ) = GlobalNameUtils::splitGlobalName( $filterName ); - // @todo Maybe add a parameter to recordProfilingResult to record global filters - // data separately (in the foreign wiki) - if ( !$global ) { - $this->recordProfilingResult( - $filterID, - $params['time'], - $params['conds'], - $params['result'] - ); - } - - if ( $params['time'] > $slowFilterThreshold ) { - $this->recordSlowFilter( - $title, - $filterName, - $params['time'], - $params['conds'], - $params['result'], - $global - ); - } + foreach ( $data as $filterName => $params ) { + list( $filterID, $global ) = GlobalNameUtils::splitGlobalName( $filterName ); + // @todo Maybe add a parameter to recordProfilingResult to record global filters + // data separately (in the foreign wiki) + if ( !$global ) { + $this->recordProfilingResult( + $filterID, + $params['time'], + $params['conds'], + $params['result'] + ); } - } ); + + if ( $params['time'] > $slowFilterThreshold ) { + $this->recordSlowFilter( + $title, + $filterName, + $params['time'], + $params['conds'], + $params['result'], + $global + ); + } + } } /** diff --git a/includes/FilterRunner.php b/includes/FilterRunner.php index 210d87a29..1ce6a3d49 100644 --- a/includes/FilterRunner.php +++ b/includes/FilterRunner.php @@ -231,12 +231,13 @@ class FilterRunner { $runnerData = $this->checkAllFiltersInternal(); } - $this->profileExecution( $runnerData ); // hack until DI for DeferredUpdates is possible (T265749) if ( defined( 'MW_PHPUNIT_TEST' ) ) { + $this->profileExecution( $runnerData ); $this->updateEmergencyCache( $runnerData->getMatchesMap() ); } else { DeferredUpdates::addCallableUpdate( function () use ( $runnerData ) { + $this->profileExecution( $runnerData ); $this->updateEmergencyCache( $runnerData->getMatchesMap() ); } ); } diff --git a/tests/phpunit/AbuseFilterFilterProfilerTest.php b/tests/phpunit/unit/FilterProfilerTest.php similarity index 96% rename from tests/phpunit/AbuseFilterFilterProfilerTest.php rename to tests/phpunit/unit/FilterProfilerTest.php index d8176c91c..c2fe9cc13 100644 --- a/tests/phpunit/AbuseFilterFilterProfilerTest.php +++ b/tests/phpunit/unit/FilterProfilerTest.php @@ -1,16 +1,22 @@ 0, @@ -70,7 +76,6 @@ class AbuseFilterFilterProfilerTest extends MediaWikiIntegrationTestCase { ], ] ); - DeferredUpdates::doUpdates(); $this->assertSame( [ 'count' => 1, @@ -109,7 +114,6 @@ class AbuseFilterFilterProfilerTest extends MediaWikiIntegrationTestCase { ], ] ); - DeferredUpdates::doUpdates(); $this->assertSame( [ 'count' => 2, @@ -181,7 +185,6 @@ class AbuseFilterFilterProfilerTest extends MediaWikiIntegrationTestCase { ], ] ); - DeferredUpdates::doUpdates(); $profiler->resetFilterProfile( 1 ); $this->assertSame( self::NULL_FILTER_PROFILE, $profiler->getFilterProfile( 1 ) ); $this->assertNotSame( self::NULL_FILTER_PROFILE, $profiler->getFilterProfile( 2 ) ); @@ -294,7 +297,6 @@ class AbuseFilterFilterProfilerTest extends MediaWikiIntegrationTestCase { ], ] ); - DeferredUpdates::doUpdates(); $profiler->recordStats( 'default', 100, 256.5, true ); $profiler->recordStats( 'default', 200, 512.5, false );