mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-27 15:30:42 +00:00
Make FilterProfiler independent of DeferredUpdate
Schedule the deferred update from FilterRunner, just like we do with EmergencyCache. Change-Id: I121211bb02a77c191001d11d4af3796e8572967e
This commit is contained in:
parent
34a2660ad2
commit
709803eb46
|
@ -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<string,array{time:float,conds:int,result:bool}> $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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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() );
|
||||
} );
|
||||
}
|
||||
|
|
|
@ -1,16 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\AbuseFilter\Tests\Unit;
|
||||
|
||||
use HashBagOStuff;
|
||||
use IBufferingStatsdDataFactory;
|
||||
use MediaWiki\Config\ServiceOptions;
|
||||
use MediaWiki\Extension\AbuseFilter\FilterProfiler;
|
||||
use MediaWikiUnitTestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\NullLogger;
|
||||
use TestLogger;
|
||||
use Title;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \MediaWiki\Extension\AbuseFilter\FilterProfiler
|
||||
* @covers ::__construct
|
||||
* @fixme convert to pure unit test when DI for DeferredUpdates is possible (T265749)
|
||||
*/
|
||||
class AbuseFilterFilterProfilerTest extends MediaWikiIntegrationTestCase {
|
||||
class FilterProfilerTest extends MediaWikiUnitTestCase {
|
||||
|
||||
private const NULL_FILTER_PROFILE = [
|
||||
'count' => 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 );
|
Loading…
Reference in a new issue