mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Linter
synced 2024-11-24 07:53:51 +00:00
Merge "Drop excess events at the API layer"
This commit is contained in:
commit
d0a19b2e37
|
@ -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',
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue