Merge "Drop excess events at the API layer"

This commit is contained in:
jenkins-bot 2018-08-21 14:10:44 +00:00 committed by Gerrit Code Review
commit d0a19b2e37
2 changed files with 10 additions and 12 deletions

View file

@ -56,10 +56,17 @@ class ApiRecordLint extends ApiBase {
$this->dieWithError( 'apierror-linter-invalid-title', 'invalid-title' );
}
$categoryMgr = new CategoryManager();
$catCounts = [];
foreach ( $data as $info ) {
if ( !$categoryMgr->isKnownCategory( $info['type'] ) ) {
continue;
}
$count = $catCounts[$info['type']] ?? 0;
if ( $count > Database::MAX_PER_CAT ) {
// Drop
continue;
}
$catCounts[$info['type']] = $count + 1;
if ( !isset( $info['dsr'] ) ) {
LoggerFactory::getInstance( 'Linter' )->warning(
'dsr for {page} @ rev {revid}, for lint: {lint} is missing',

View file

@ -42,7 +42,7 @@ class RecordLintJob extends Job {
return true;
}
// [ 'category' => [ 'id' => LintError ] ]
// [ 'id' => LintError ]
$errors = [];
foreach ( $this->params['errors'] as $errorInfo ) {
$error = new LintError(
@ -52,19 +52,10 @@ class RecordLintJob extends Job {
);
// Use unique id as key to get rid of exact dupes
// (e.g. same category of error in same template)
$errors[$error->category][$error->id()] = $error;
$errors[$error->id()] = $error;
}
$lintDb = new Database( $this->title->getArticleID() );
$toSet = [];
foreach ( $errors as $category => $catErrors ) {
// If there are too many errors for a category, trim some of them.
if ( count( $catErrors ) > $lintDb::MAX_PER_CAT ) {
$catErrors = array_slice( $catErrors, 0, $lintDb::MAX_PER_CAT );
}
$toSet = array_merge( $toSet, $catErrors );
}
$changes = $lintDb->setForPage( $toSet );
$changes = $lintDb->setForPage( $errors );
$this->updateStats( $lintDb, $changes );
return true;