Merge "Do not serialize RunnerData to array in FilterRunner"

This commit is contained in:
jenkins-bot 2021-02-20 14:47:15 +00:00 committed by Gerrit Code Review
commit 8575201ab2
3 changed files with 66 additions and 18 deletions

View file

@ -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
);
}

View file

@ -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[]
*/

View file

@ -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
);
}
}