mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Linter
synced 2024-11-27 17:20:12 +00:00
Fix lint error updating
The article id of the title is set to 0 when the page is deleted so, although the lint job from the hook runs, it doesn't remove anything. Reverts most of I06b821b65f65609ddac8ed4e7c662336082d8266 Bug: T298782 Bug: T170313 Change-Id: I2610b9b16d4032b0e18b3537cc9ed51bfdaff299
This commit is contained in:
parent
2218e87c05
commit
fc8c39baa5
|
@ -22,6 +22,8 @@ namespace MediaWiki\Linter;
|
|||
|
||||
use FormatJson;
|
||||
use MediaWiki\Logger\LoggerFactory;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use WikiMap;
|
||||
|
||||
/**
|
||||
* Database logic
|
||||
|
@ -319,4 +321,55 @@ class Database {
|
|||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send stats to statsd and update totals cache
|
||||
*
|
||||
* @param array $changes
|
||||
*/
|
||||
public function updateStats( array $changes ) {
|
||||
global $wgLinterStatsdSampleFactor;
|
||||
|
||||
$mwServices = MediaWikiServices::getInstance();
|
||||
|
||||
$totalsLookup = new TotalsLookup(
|
||||
new CategoryManager(),
|
||||
$mwServices->getMainWANObjectCache()
|
||||
);
|
||||
|
||||
if ( $wgLinterStatsdSampleFactor === false ) {
|
||||
// Don't send to statsd, but update cache with $changes
|
||||
$raw = $changes['added'];
|
||||
foreach ( $changes['deleted'] as $cat => $count ) {
|
||||
if ( isset( $raw[$cat] ) ) {
|
||||
$raw[$cat] -= $count;
|
||||
} else {
|
||||
// Negative value
|
||||
$raw[$cat] = 0 - $count;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $raw as $cat => $count ) {
|
||||
if ( $count != 0 ) {
|
||||
// There was a change in counts, invalidate the cache
|
||||
$totalsLookup->touchCategoryCache( $cat );
|
||||
}
|
||||
}
|
||||
return;
|
||||
} elseif ( mt_rand( 1, $wgLinterStatsdSampleFactor ) != 1 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$totals = $this->getTotals();
|
||||
$wiki = WikiMap::getCurrentWikiId();
|
||||
|
||||
$stats = $mwServices->getStatsdDataFactory();
|
||||
foreach ( $totals as $name => $count ) {
|
||||
$stats->gauge( "linter.category.$name.$wiki", $count );
|
||||
}
|
||||
|
||||
$stats->gauge( "linter.totals.$wiki", array_sum( $totals ) );
|
||||
|
||||
$totalsLookup->touchAllCategoriesCache();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -96,12 +96,10 @@ class Hooks {
|
|||
public static function onWikiPageDeletionUpdates( WikiPage $wikiPage,
|
||||
Content $content, array &$updates
|
||||
) {
|
||||
$title = $wikiPage->getTitle();
|
||||
$updates[] = new MWCallableUpdate( static function () use ( $title ) {
|
||||
$job = new RecordLintJob(
|
||||
$title, [ 'errors' => [] ]
|
||||
);
|
||||
$job->run();
|
||||
$id = $wikiPage->getId();
|
||||
$updates[] = new MWCallableUpdate( static function () use ( $id ) {
|
||||
$database = new Database( $id );
|
||||
$database->updateStats( $database->setForPage( [] ) );
|
||||
}, __METHOD__ );
|
||||
}
|
||||
|
||||
|
|
|
@ -21,9 +21,7 @@
|
|||
namespace MediaWiki\Linter;
|
||||
|
||||
use Job;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Title;
|
||||
use WikiMap;
|
||||
|
||||
class RecordLintJob extends Job {
|
||||
/**
|
||||
|
@ -36,9 +34,7 @@ class RecordLintJob extends Job {
|
|||
}
|
||||
|
||||
public function run() {
|
||||
if ( isset( $this->params['revision'] )
|
||||
&& $this->title->getLatestRevID() != $this->params['revision']
|
||||
) {
|
||||
if ( $this->title->getLatestRevID() != $this->params['revision'] ) {
|
||||
// Outdated now, let a later job handle it
|
||||
return true;
|
||||
}
|
||||
|
@ -56,63 +52,11 @@ class RecordLintJob extends Job {
|
|||
// (e.g. same category of error in same template)
|
||||
$errors[$error->id()] = $error;
|
||||
}
|
||||
|
||||
$lintDb = new Database( $this->title->getArticleID() );
|
||||
$changes = $lintDb->setForPage( $errors );
|
||||
$this->updateStats( $lintDb, $changes );
|
||||
$lintDb->updateStats( $lintDb->setForPage( $errors ) );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send stats to statsd and update totals cache
|
||||
*
|
||||
* @param Database $lintDb
|
||||
* @param array $changes
|
||||
*/
|
||||
protected function updateStats( Database $lintDb, array $changes ) {
|
||||
global $wgLinterStatsdSampleFactor;
|
||||
|
||||
$mwServices = MediaWikiServices::getInstance();
|
||||
|
||||
$totalsLookup = new TotalsLookup(
|
||||
new CategoryManager(),
|
||||
$mwServices->getMainWANObjectCache()
|
||||
);
|
||||
|
||||
if ( $wgLinterStatsdSampleFactor === false ) {
|
||||
// Don't send to statsd, but update cache with $changes
|
||||
$raw = $changes['added'];
|
||||
foreach ( $changes['deleted'] as $cat => $count ) {
|
||||
if ( isset( $raw[$cat] ) ) {
|
||||
$raw[$cat] -= $count;
|
||||
} else {
|
||||
// Negative value
|
||||
$raw[$cat] = 0 - $count;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $raw as $cat => $count ) {
|
||||
if ( $count != 0 ) {
|
||||
// There was a change in counts, invalidate the cache
|
||||
$totalsLookup->touchCategoryCache( $cat );
|
||||
}
|
||||
}
|
||||
return;
|
||||
} elseif ( mt_rand( 1, $wgLinterStatsdSampleFactor ) != 1 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$totals = $lintDb->getTotals();
|
||||
$wiki = WikiMap::getCurrentWikiId();
|
||||
|
||||
$stats = $mwServices->getStatsdDataFactory();
|
||||
foreach ( $totals as $name => $count ) {
|
||||
$stats->gauge( "linter.category.$name.$wiki", $count );
|
||||
}
|
||||
|
||||
$stats->gauge( "linter.totals.$wiki", array_sum( $totals ) );
|
||||
|
||||
$totalsLookup->touchAllCategoriesCache();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue