title->getLatestRevID() != $this->params['revision'] ) { // Outdated now, let a later job handle it return true; } // [ 'category' => [ 'id' => LintError ] ] $errors = []; foreach ( $this->params['errors'] as $errorInfo ) { $error = new LintError( $errorInfo['type'], $errorInfo['location'], $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() ); $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 ); $this->updateStats( $lintDb ); return true; } /** * Send stats to statsd * * @param Database $lintDb */ protected function updateStats( Database $lintDb ) { global $wgLinterStatsdSampleFactor; if ( $wgLinterStatsdSampleFactor === false ) { // Not enabled at all return; } elseif ( mt_rand( 1, $wgLinterStatsdSampleFactor ) != 1 ) { return; } $totals = $lintDb->getTotals(); $wiki = wfWikiID(); $stats = MediaWikiServices::getInstance()->getStatsdDataFactory(); foreach ( $totals as $name => $count ) { $stats->gauge( "linter.category.$name.$wiki", $count ); } $stats->gauge( "linter.totals.$wiki", array_sum( $totals ) ); } }