Merge "De-duplicate errors and trim excessive errors in the same category"

This commit is contained in:
jenkins-bot 2016-11-24 14:56:49 +00:00 committed by Gerrit Code Review
commit 603f480f5b
2 changed files with 25 additions and 5 deletions

View file

@ -26,6 +26,13 @@ use FormatJson;
* Database logic
*/
class Database {
/**
* Maximum number of errors to save per category,
* for a page, the rest are just dropped
*/
const MAX_PER_CAT = 20;
/**
* @var int
*/

View file

@ -39,15 +39,28 @@ class RecordLintJob extends Job {
return true;
}
// [ 'category' => [ 'id' => LintError ] ]
$errors = [];
foreach ( $this->params['errors'] as $error ) {
$errors[] = new LintError(
$error['type'],
$error['params']
foreach ( $this->params['errors'] as $errorInfo ) {
$error = new LintError(
$errorInfo['type'],
$errorInfo['params']
);
// 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;
}
$lintDb = new Database( $this->title->getArticleID() );
$lintDb->setForPage( $errors );
$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 );
}
$lintDb->setForPage( $toSet );
return true;
}