mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Linter
synced 2024-11-28 09:40:20 +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' );
|
$this->dieWithError( 'apierror-linter-invalid-title', 'invalid-title' );
|
||||||
}
|
}
|
||||||
$categoryMgr = new CategoryManager();
|
$categoryMgr = new CategoryManager();
|
||||||
|
$catCounts = [];
|
||||||
foreach ( $data as $info ) {
|
foreach ( $data as $info ) {
|
||||||
if ( !$categoryMgr->isKnownCategory( $info['type'] ) ) {
|
if ( !$categoryMgr->isKnownCategory( $info['type'] ) ) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
$count = $catCounts[$info['type']] ?? 0;
|
||||||
|
if ( $count > Database::MAX_PER_CAT ) {
|
||||||
|
// Drop
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$catCounts[$info['type']] = $count + 1;
|
||||||
if ( !isset( $info['dsr'] ) ) {
|
if ( !isset( $info['dsr'] ) ) {
|
||||||
LoggerFactory::getInstance( 'Linter' )->warning(
|
LoggerFactory::getInstance( 'Linter' )->warning(
|
||||||
'dsr for {page} @ rev {revid}, for lint: {lint} is missing',
|
'dsr for {page} @ rev {revid}, for lint: {lint} is missing',
|
||||||
|
|
|
@ -42,7 +42,7 @@ class RecordLintJob extends Job {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// [ 'category' => [ 'id' => LintError ] ]
|
// [ 'id' => LintError ]
|
||||||
$errors = [];
|
$errors = [];
|
||||||
foreach ( $this->params['errors'] as $errorInfo ) {
|
foreach ( $this->params['errors'] as $errorInfo ) {
|
||||||
$error = new LintError(
|
$error = new LintError(
|
||||||
|
@ -52,19 +52,10 @@ class RecordLintJob extends Job {
|
||||||
);
|
);
|
||||||
// Use unique id as key to get rid of exact dupes
|
// Use unique id as key to get rid of exact dupes
|
||||||
// (e.g. same category of error in same template)
|
// (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() );
|
$lintDb = new Database( $this->title->getArticleID() );
|
||||||
$toSet = [];
|
$changes = $lintDb->setForPage( $errors );
|
||||||
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 );
|
|
||||||
$this->updateStats( $lintDb, $changes );
|
$this->updateStats( $lintDb, $changes );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue