Merge "Add action/user tracking to html cache purge jobs"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 9 Nov 2017 22:33:48 +0000 (22:33 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 9 Nov 2017 22:33:48 +0000 (22:33 +0000)
includes/Title.php
includes/deferred/HTMLCacheUpdate.php
includes/deferred/LinksUpdate.php
includes/filerepo/file/File.php
includes/filerepo/file/LocalFile.php
includes/jobqueue/jobs/HTMLCacheUpdateJob.php
includes/page/PageArchive.php
includes/page/WikiFilePage.php
includes/page/WikiPage.php

index d043b44..829be44 100644 (file)
@@ -4622,9 +4622,11 @@ class Title implements LinkTarget {
         * on the number of links. Typically called on create and delete.
         */
        public function touchLinks() {
-               DeferredUpdates::addUpdate( new HTMLCacheUpdate( $this, 'pagelinks' ) );
+               DeferredUpdates::addUpdate( new HTMLCacheUpdate( $this, 'pagelinks', 'page-touch' ) );
                if ( $this->getNamespace() == NS_CATEGORY ) {
-                       DeferredUpdates::addUpdate( new HTMLCacheUpdate( $this, 'categorylinks' ) );
+                       DeferredUpdates::addUpdate(
+                               new HTMLCacheUpdate( $this, 'categorylinks', 'category-touch' )
+                       );
                }
        }
 
index db3790f..29846bf 100644 (file)
@@ -26,7 +26,7 @@
  *
  * @ingroup Cache
  */
-class HTMLCacheUpdate implements DeferrableUpdate {
+class HTMLCacheUpdate extends DataUpdate {
        /** @var Title */
        public $mTitle;
 
@@ -36,14 +36,24 @@ class HTMLCacheUpdate implements DeferrableUpdate {
        /**
         * @param Title $titleTo
         * @param string $table
+        * @param string $causeAction Triggering action
+        * @param string $causeAgent Triggering user
         */
-       function __construct( Title $titleTo, $table ) {
+       function __construct(
+               Title $titleTo, $table, $causeAction = 'unknown', $causeAgent = 'unknown'
+       ) {
                $this->mTitle = $titleTo;
                $this->mTable = $table;
+               $this->causeAction = $causeAction;
+               $this->causeAgent = $causeAgent;
        }
 
        public function doUpdate() {
-               $job = HTMLCacheUpdateJob::newForBacklinks( $this->mTitle, $this->mTable );
+               $job = HTMLCacheUpdateJob::newForBacklinks(
+                       $this->mTitle,
+                       $this->mTable,
+                       [ 'causeAction' => $this->getCauseAction(), 'causeAgent' => $this->getCauseAgent() ]
+               );
 
                JobQueueGroup::singleton()->lazyPush( $job );
        }
index c27826d..8913642 100644 (file)
@@ -1055,7 +1055,9 @@ class LinksUpdate extends DataUpdate implements EnqueueableDataUpdate {
                                        $inv = [ $inv ];
                                }
                                foreach ( $inv as $table ) {
-                                       DeferredUpdates::addUpdate( new HTMLCacheUpdate( $this->mTitle, $table ) );
+                                       DeferredUpdates::addUpdate(
+                                               new HTMLCacheUpdate( $this->mTitle, $table, 'page-props' )
+                                       );
                                }
                        }
                }
index 32f4504..54bd0a5 100644 (file)
@@ -1445,7 +1445,9 @@ abstract class File implements IDBAccessObject {
                // Purge cache of all pages using this file
                $title = $this->getTitle();
                if ( $title ) {
-                       DeferredUpdates::addUpdate( new HTMLCacheUpdate( $title, 'imagelinks' ) );
+                       DeferredUpdates::addUpdate(
+                               new HTMLCacheUpdate( $title, 'imagelinks', 'file-purge' )
+                       );
                }
        }
 
index 44c90af..bb12515 100644 (file)
@@ -1740,7 +1740,9 @@ class LocalFile extends File {
                }
 
                # Invalidate cache for all pages using this file
-               DeferredUpdates::addUpdate( new HTMLCacheUpdate( $this->getTitle(), 'imagelinks' ) );
+               DeferredUpdates::addUpdate(
+                       new HTMLCacheUpdate( $this->getTitle(), 'imagelinks', 'file-upload' )
+               );
 
                return Status::newGood();
        }
index 4d75cb3..34028df 100644 (file)
@@ -47,14 +47,16 @@ class HTMLCacheUpdateJob extends Job {
                        // Multiple pages per job make matches unlikely
                        !( isset( $params['pages'] ) && count( $params['pages'] ) != 1 )
                );
+               $this->params += [ 'causeAction' => 'unknown', 'causeAgent' => 'unknown' ];
        }
 
        /**
         * @param Title $title Title to purge backlink pages from
         * @param string $table Backlink table name
+        * @param array $params Additional job parameters
         * @return HTMLCacheUpdateJob
         */
-       public static function newForBacklinks( Title $title, $table ) {
+       public static function newForBacklinks( Title $title, $table, $params = [] ) {
                return new self(
                        $title,
                        [
@@ -62,7 +64,7 @@ class HTMLCacheUpdateJob extends Job {
                                'recursive' => true
                        ] + Job::newRootJobParams( // "overall" refresh links job info
                                "htmlCacheUpdate:{$table}:{$title->getPrefixedText()}"
-                       )
+                       ) + $params
                );
        }
 
@@ -75,6 +77,11 @@ class HTMLCacheUpdateJob extends Job {
 
                // 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['causeAgent'] = $this->params['causeAgent'];
                        // 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(
@@ -82,7 +89,7 @@ class HTMLCacheUpdateJob extends Job {
                                $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
index 209551b..c03d6b2 100644 (file)
@@ -764,7 +764,9 @@ class PageArchive {
                        Hooks::run( 'ArticleUndelete',
                                [ &$this->title, $created, $comment, $oldPageId, $restoredPages ] );
                        if ( $this->title->getNamespace() == NS_FILE ) {
-                               DeferredUpdates::addUpdate( new HTMLCacheUpdate( $this->title, 'imagelinks' ) );
+                               DeferredUpdates::addUpdate(
+                                       new HTMLCacheUpdate( $this->title, 'imagelinks', 'file-restore' )
+                               );
                        }
                }
 
index 972a397..4c2ebdc 100644 (file)
@@ -173,7 +173,9 @@ class WikiFilePage extends WikiPage {
 
                if ( $this->mFile->exists() ) {
                        wfDebug( 'ImagePage::doPurge purging ' . $this->mFile->getName() . "\n" );
-                       DeferredUpdates::addUpdate( new HTMLCacheUpdate( $this->mTitle, 'imagelinks' ) );
+                       DeferredUpdates::addUpdate(
+                               new HTMLCacheUpdate( $this->mTitle, 'imagelinks', 'file-purge' )
+                       );
                } else {
                        wfDebug( 'ImagePage::doPurge no image for '
                                . $this->mFile->getName() . "; limiting purge to cache only\n" );
index 95b7be2..8b34928 100644 (file)
@@ -3317,7 +3317,9 @@ class WikiPage implements Page, IDBAccessObject {
                MediaWikiServices::getInstance()->getLinkCache()->invalidateTitle( $title );
 
                // Invalidate caches of articles which include this page
-               DeferredUpdates::addUpdate( new HTMLCacheUpdate( $title, 'templatelinks' ) );
+               DeferredUpdates::addUpdate(
+                       new HTMLCacheUpdate( $title, 'templatelinks', 'page-create' )
+               );
 
                if ( $title->getNamespace() == NS_CATEGORY ) {
                        // Load the Category object, which will schedule a job to create
@@ -3355,7 +3357,9 @@ class WikiPage implements Page, IDBAccessObject {
 
                // Images
                if ( $title->getNamespace() == NS_FILE ) {
-                       DeferredUpdates::addUpdate( new HTMLCacheUpdate( $title, 'imagelinks' ) );
+                       DeferredUpdates::addUpdate(
+                               new HTMLCacheUpdate( $title, 'imagelinks', 'page-delete' )
+                       );
                }
 
                // User talk pages
@@ -3378,10 +3382,14 @@ class WikiPage implements Page, IDBAccessObject {
         */
        public static function onArticleEdit( Title $title, Revision $revision = null ) {
                // Invalidate caches of articles which include this page
-               DeferredUpdates::addUpdate( new HTMLCacheUpdate( $title, 'templatelinks' ) );
+               DeferredUpdates::addUpdate(
+                       new HTMLCacheUpdate( $title, 'templatelinks', 'page-edit' )
+               );
 
                // Invalidate the caches of all pages which redirect here
-               DeferredUpdates::addUpdate( new HTMLCacheUpdate( $title, 'redirect' ) );
+               DeferredUpdates::addUpdate(
+                       new HTMLCacheUpdate( $title, 'redirect', 'page-edit' )
+               );
 
                MediaWikiServices::getInstance()->getLinkCache()->invalidateTitle( $title );