mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-11-23 21:53:35 +00:00
Do not serialize RunnerData to array in FilterRunner
Change-Id: Ia803042224959e516bc14bdc034421b8e80390a8
This commit is contained in:
parent
431226ac39
commit
c18e4a4a5f
|
@ -225,20 +225,15 @@ class FilterRunner {
|
|||
$runnerData = $this->checkAllFiltersInternal();
|
||||
}
|
||||
|
||||
// TODO: get rid of this
|
||||
$result = $runnerData->toArray();
|
||||
$result['matches'] = $runnerData->getMatchesMap();
|
||||
|
||||
$matchedFilters = array_keys( array_filter( $result['matches'] ) );
|
||||
$allFilters = array_keys( $result['matches'] );
|
||||
|
||||
$this->profileExecution( $result, $matchedFilters, $allFilters );
|
||||
$this->profileExecution( $runnerData );
|
||||
|
||||
// Tag the action if the condition limit was hit
|
||||
if ( $result['condCount'] > $this->options->get( 'AbuseFilterConditionLimit' ) ) {
|
||||
if ( $runnerData->getTotalConditions() > $this->options->get( 'AbuseFilterConditionLimit' ) ) {
|
||||
$this->changeTagger->addConditionsLimitTag( $this->getSpecsForTagger() );
|
||||
}
|
||||
|
||||
$matchedFilters = $runnerData->getMatchedFilters();
|
||||
|
||||
if ( count( $matchedFilters ) === 0 ) {
|
||||
return Status::newGood();
|
||||
}
|
||||
|
@ -380,22 +375,22 @@ class FilterRunner {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param array $result Result of the execution, as created in run()
|
||||
* @param string[] $matchedFilters
|
||||
* @param string[] $allFilters
|
||||
* @param RunnerData $data
|
||||
*/
|
||||
protected function profileExecution( array $result, array $matchedFilters, array $allFilters ) {
|
||||
protected function profileExecution( RunnerData $data ) {
|
||||
$allFilters = $data->getAllFilters();
|
||||
$matchedFilters = $data->getMatchedFilters();
|
||||
$this->filterProfiler->checkResetProfiling( $this->group, $allFilters );
|
||||
$this->filterProfiler->recordRuntimeProfilingResult(
|
||||
count( $allFilters ),
|
||||
$result['condCount'],
|
||||
$result['runtime']
|
||||
$data->getTotalConditions(),
|
||||
$data->getTotalRunTime()
|
||||
);
|
||||
$this->filterProfiler->recordPerFilterProfiling( $this->title, $result['profiling'] );
|
||||
$this->filterProfiler->recordPerFilterProfiling( $this->title, $data->getProfilingData() );
|
||||
$this->filterProfiler->recordStats(
|
||||
$this->group,
|
||||
$result['condCount'],
|
||||
$result['runtime'],
|
||||
$data->getTotalConditions(),
|
||||
$data->getTotalRunTime(),
|
||||
(bool)$matchedFilters
|
||||
);
|
||||
}
|
||||
|
|
|
@ -80,6 +80,20 @@ class RunnerData {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getAllFilters() : array {
|
||||
return array_keys( $this->matchedFilters );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getMatchedFilters() : array {
|
||||
return array_keys( array_filter( $this->getMatchesMap() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array[]
|
||||
*/
|
||||
|
|
|
@ -114,4 +114,43 @@ class RunnerDataTest extends MediaWikiUnitTestCase {
|
|||
$this->assertSame( $runnerData->getMatchesMap(), $newData->getMatchesMap() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getAllFilters
|
||||
* @covers ::getMatchedFilters
|
||||
*/
|
||||
public function testGetAllAndMatchedFilters() {
|
||||
$runnerData = new RunnerData();
|
||||
$runnerData->record(
|
||||
1, false,
|
||||
new ParserStatus( true, false, null, [] ),
|
||||
[ 'time' => 12.3, 'conds' => 7 ]
|
||||
);
|
||||
$runnerData->record(
|
||||
1, true,
|
||||
new ParserStatus( false, false, null, [] ),
|
||||
[ 'time' => 23.4, 'conds' => 5 ]
|
||||
);
|
||||
$runnerData->record(
|
||||
3, false,
|
||||
new ParserStatus( false, false, null, [] ),
|
||||
[ 'time' => 12.3, 'conds' => 7 ]
|
||||
);
|
||||
$runnerData->record(
|
||||
3, true,
|
||||
new ParserStatus( true, false, null, [] ),
|
||||
[ 'time' => 23.4, 'conds' => 5 ]
|
||||
);
|
||||
|
||||
$this->assertArrayEquals(
|
||||
[ '1', 'global-1', '3', 'global-3' ],
|
||||
$runnerData->getAllFilters(),
|
||||
false
|
||||
);
|
||||
$this->assertArrayEquals(
|
||||
[ '1', 'global-3' ],
|
||||
$runnerData->getMatchedFilters(),
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue