Aaron Schulz has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/385248 )
Change subject: Add action/user tracking to link refresh jobs ...................................................................... Add action/user tracking to link refresh jobs Change-Id: Ie7261eacddb869988b005ba2f17968df88c7003e --- M includes/api/ApiPurge.php M includes/deferred/DataUpdate.php M includes/deferred/LinksUpdate.php M includes/filerepo/file/LocalFile.php M includes/jobqueue/jobs/HTMLCacheUpdateJob.php M includes/jobqueue/jobs/RefreshLinksJob.php M includes/page/WikiPage.php 7 files changed, 91 insertions(+), 13 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/48/385248/1 diff --git a/includes/api/ApiPurge.php b/includes/api/ApiPurge.php index 35f93e0..4b8ce7f 100644 --- a/includes/api/ApiPurge.php +++ b/includes/api/ApiPurge.php @@ -93,6 +93,7 @@ $updates = $content->getSecondaryDataUpdates( $title, null, $forceRecursiveLinkUpdate, $p_result ); foreach ( $updates as $update ) { + $update->setCause( 'api-purge', $this->getUser()->getName() ); DeferredUpdates::addUpdate( $update, DeferredUpdates::PRESEND ); } diff --git a/includes/deferred/DataUpdate.php b/includes/deferred/DataUpdate.php index d2d8bd7..ffa3f9f 100644 --- a/includes/deferred/DataUpdate.php +++ b/includes/deferred/DataUpdate.php @@ -28,6 +28,10 @@ abstract class DataUpdate implements DeferrableUpdate { /** @var mixed Result from LBFactory::getEmptyTransactionTicket() */ protected $ticket; + /** @var string Short update cause action description */ + protected $causeAction = 'unknown'; + /** @var string Short update cause user description */ + protected $causeUser = 'unknown'; public function __construct() { // noop @@ -42,6 +46,29 @@ } /** + * @param string $action Action type + * @param string $user User name + */ + public function setCause( $action, $user ) { + $this->causeAction = $action; + $this->causeUser = $user; + } + + /** + * @return string + */ + public function getCauseAction() { + return $this->causeAction; + } + + /** + * @return string + */ + public function getCauseUser() { + return $this->causeUser; + } + + /** * Convenience method, calls doUpdate() on every DataUpdate in the array. * * @param DataUpdate[] $updates A list of DataUpdate instances diff --git a/includes/deferred/LinksUpdate.php b/includes/deferred/LinksUpdate.php index dfe89ba..f396fc8 100644 --- a/includes/deferred/LinksUpdate.php +++ b/includes/deferred/LinksUpdate.php @@ -306,10 +306,13 @@ * using the job queue. */ protected function queueRecursiveJobs() { - self::queueRecursiveJobsForTable( $this->mTitle, 'templatelinks' ); + $action = $this->getCauseAction(); + $userName = $this->getCauseUser(); + + self::queueRecursiveJobsForTable( $this->mTitle, 'templatelinks', $action, $userName ); if ( $this->mTitle->getNamespace() == NS_FILE ) { // Process imagelinks in case the title is or was a redirect - self::queueRecursiveJobsForTable( $this->mTitle, 'imagelinks' ); + self::queueRecursiveJobsForTable( $this->mTitle, 'imagelinks', $action, $userName ); } $bc = $this->mTitle->getBacklinkCache(); @@ -320,7 +323,10 @@ // Which ever runs first generally no-ops the other one. $jobs = []; foreach ( $bc->getCascadeProtectedLinks() as $title ) { - $jobs[] = RefreshLinksJob::newPrioritized( $title, [] ); + $jobs[] = RefreshLinksJob::newPrioritized( + $title, + [ 'causeAction' => $this->getCauseAction(), 'causeUser' => $this->getCauseUser() ] + ); } JobQueueGroup::singleton()->push( $jobs ); } @@ -330,8 +336,12 @@ * * @param Title $title Title to do job for * @param string $table Table to use (e.g. 'templatelinks') + * @param array $action Triggering action + * @param array $userName Triggering user name */ - public static function queueRecursiveJobsForTable( Title $title, $table ) { + public static function queueRecursiveJobsForTable( + Title $title, $table, $action = 'unknown', $userName = 'unknown' + ) { if ( $title->getBacklinkCache()->hasLinks( $table ) ) { $job = new RefreshLinksJob( $title, @@ -340,7 +350,7 @@ 'recursive' => true, ] + Job::newRootJobParams( // "overall" refresh links job info "refreshlinks:{$table}:{$title->getPrefixedText()}" - ) + ) + [ 'causeAction' => $action, 'causeUser' => $userName ] ); JobQueueGroup::singleton()->push( $job ); diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index 410a794..a30deed 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -1646,7 +1646,12 @@ ); } else { # Update backlink pages pointing to this title if created - LinksUpdate::queueRecursiveJobsForTable( $this->getTitle(), 'imagelinks' ); + LinksUpdate::queueRecursiveJobsForTable( + $this->getTitle(), + 'imagelinks', + 'upload-image', + $user->getName() + ); } $this->prerenderThumbnails(); diff --git a/includes/jobqueue/jobs/HTMLCacheUpdateJob.php b/includes/jobqueue/jobs/HTMLCacheUpdateJob.php index e8edab5..026b9e7 100644 --- a/includes/jobqueue/jobs/HTMLCacheUpdateJob.php +++ b/includes/jobqueue/jobs/HTMLCacheUpdateJob.php @@ -47,6 +47,7 @@ // Multiple pages per job make matches unlikely !( isset( $params['pages'] ) && count( $params['pages'] ) != 1 ) ); + $this->params += [ 'causeAction' => 'unknown', 'causeUser' => 'unknown' ]; } /** @@ -75,14 +76,18 @@ // Job to purge all (or a range of) backlink pages for a page if ( !empty( $this->params['recursive'] ) ) { + // Carry over information for de-duplication + $extraParams = $this->getRootJobParams(); + // Carry over cause information for logging + $extraParams['causeAction'] = $this->params['causeAction']; + $extraParams['causeUser'] = $this->params['causeUser']; // Convert this into no more than $wgUpdateRowsPerJob HTMLCacheUpdateJob per-title // jobs and possibly a recursive HTMLCacheUpdateJob job for the rest of the backlinks $jobs = BacklinkJobUtils::partitionBacklinkJob( $this, $wgUpdateRowsPerJob, $wgUpdateRowsPerQuery, // jobs-per-title - // Carry over information for de-duplication - [ 'params' => $this->getRootJobParams() ] + [ 'params' => $extraParams ] ); JobQueueGroup::singleton()->push( $jobs ); // Job to purge pages for a set of titles @@ -169,6 +174,22 @@ } } + public function getDeduplicationInfo() { + $info = parent::getDeduplicationInfo(); + unset( $info['causeAction'] ); + unset( $info['causeUser'] ); + if ( is_array( $info['params'] ) ) { + // For per-pages jobs, the job title is that of the template that changed + // (or similar), so remove that since it ruins duplicate detection + if ( isset( $info['pages'] ) ) { + unset( $info['namespace'] ); + unset( $info['title'] ); + } + } + + return $info; + } + public function workItemCount() { if ( !empty( $this->params['recursive'] ) ) { return 0; // nothing actually purged diff --git a/includes/jobqueue/jobs/RefreshLinksJob.php b/includes/jobqueue/jobs/RefreshLinksJob.php index 424fcec..ac2fb29 100644 --- a/includes/jobqueue/jobs/RefreshLinksJob.php +++ b/includes/jobqueue/jobs/RefreshLinksJob.php @@ -53,6 +53,7 @@ // Multiple pages per job make matches unlikely !( isset( $params['pages'] ) && count( $params['pages'] ) != 1 ) ); + $this->params += [ 'causeAction' => 'unknown', 'causeUser' => 'unknown' ]; } /** @@ -102,6 +103,9 @@ // Carry over information for de-duplication $extraParams = $this->getRootJobParams(); $extraParams['triggeredRecursive'] = true; + // Carry over cause information for logging + $extraParams['causeAction'] = $this->params['causeAction']; + $extraParams['causeUser'] = $this->params['causeUser']; // Convert this into no more than $wgUpdateRowsPerJob RefreshLinks per-title // jobs and possibly a recursive RefreshLinks job for the rest of the backlinks $jobs = BacklinkJobUtils::partitionBacklinkJob( @@ -254,6 +258,8 @@ $lbFactory->commitAndWaitForReplication( __METHOD__, $ticket ); foreach ( $updates as $update ) { + // Carry over cause in case so the update can do extra logging + $update->setCause( $this->params['causeAction'], $this->params['causeUser'] ); // FIXME: This code probably shouldn't be here? // Needed by things like Echo notifications which need // to know which user caused the links update @@ -288,6 +294,8 @@ public function getDeduplicationInfo() { $info = parent::getDeduplicationInfo(); + unset( $info['causeAction'] ); + unset( $info['causeUser'] ); if ( is_array( $info['params'] ) ) { // For per-pages jobs, the job title is that of the template that changed // (or similar), so remove that since it ruins duplicate detection diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index d0a04c0..39d191b 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -2171,6 +2171,7 @@ $this->getTitle(), null, $recursive, $editInfo->output ); foreach ( $updates as $update ) { + $update->setCause( 'edit-page', $user->getName() ); if ( $update instanceof LinksUpdate ) { $update->setRevision( $revision ); $update->setTriggeringUser( $user ); @@ -2913,7 +2914,7 @@ $dbw->endAtomic( __METHOD__ ); - $this->doDeleteUpdates( $id, $content, $revision ); + $this->doDeleteUpdates( $id, $content, $revision, $user ); Hooks::run( 'ArticleDeleteComplete', [ &$wikiPageBeforeDelete, @@ -2964,8 +2965,11 @@ * the required updates. This may be needed because $this->getContent() * may already return null when the page proper was deleted. * @param Revision|null $revision The latest page revision + * @param User|null $user The user that caused the deletion */ - public function doDeleteUpdates( $id, Content $content = null, Revision $revision = null ) { + public function doDeleteUpdates( + $id, Content $content = null, Revision $revision = null, User $user = null + ) { try { $countable = $this->isCountable(); } catch ( Exception $ex ) { @@ -2983,12 +2987,14 @@ DeferredUpdates::addUpdate( $update ); } + $causeUser = $user ? $user->getName() : 'unknown'; // Reparse any pages transcluding this page - LinksUpdate::queueRecursiveJobsForTable( $this->mTitle, 'templatelinks' ); - + LinksUpdate::queueRecursiveJobsForTable( + $this->mTitle, 'templatelinks', 'delete-page', $causeUser ); // Reparse any pages including this image if ( $this->mTitle->getNamespace() == NS_FILE ) { - LinksUpdate::queueRecursiveJobsForTable( $this->mTitle, 'imagelinks' ); + LinksUpdate::queueRecursiveJobsForTable( + $this->mTitle, 'imagelinks', 'delete-page', $causeUser ); } // Clear caches -- To view, visit https://gerrit.wikimedia.org/r/385248 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie7261eacddb869988b005ba2f17968df88c7003e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits