Revert "Split out new RefreshSecondaryDataUpdate class"
authorTimo Tijhof <krinklemail@gmail.com>
Tue, 19 Mar 2019 03:01:43 +0000 (03:01 +0000)
committerTimo Tijhof <krinklemail@gmail.com>
Tue, 19 Mar 2019 14:51:27 +0000 (14:51 +0000)
This reverts commits a1f7fd3adaa30ef02cd018901.

Bug: T218456
Change-Id: I9bbea3d13460ed44755d77fc61ff23fb906cf71e

autoload.php
includes/Storage/DerivedPageDataUpdater.php
includes/deferred/DeferredUpdates.php
includes/deferred/LinksUpdate.php
includes/deferred/RefreshSecondaryDataUpdate.php [deleted file]

index 8e771a3..4172ed3 100644 (file)
@@ -1215,7 +1215,6 @@ $wgAutoloadLocalClasses = [
        'RefreshImageMetadata' => __DIR__ . '/maintenance/refreshImageMetadata.php',
        'RefreshLinks' => __DIR__ . '/maintenance/refreshLinks.php',
        'RefreshLinksJob' => __DIR__ . '/includes/jobqueue/jobs/RefreshLinksJob.php',
-       'RefreshSecondaryDataUpdate' => __DIR__ . '/includes/deferred/RefreshSecondaryDataUpdate.php',
        'RegexlikeReplacer' => __DIR__ . '/includes/libs/replacers/RegexlikeReplacer.php',
        'RemexStripTagHandler' => __DIR__ . '/includes/parser/RemexStripTagHandler.php',
        'RemoveInvalidEmails' => __DIR__ . '/maintenance/removeInvalidEmails.php',
index 8dedc70..9ce12b4 100644 (file)
@@ -24,7 +24,6 @@ namespace MediaWiki\Storage;
 
 use ApiStashEdit;
 use CategoryMembershipChangeJob;
-use RefreshSecondaryDataUpdate;
 use Content;
 use ContentHandler;
 use DataUpdate;
@@ -1591,31 +1590,14 @@ class DerivedPageDataUpdater implements IDBAccessObject {
                                $update->setRevision( $legacyRevision );
                                $update->setTriggeringUser( $triggeringUser );
                        }
-               }
-
-               if ( $options['defer'] === false ) {
-                       foreach ( $updates as $update ) {
-                               if ( $update instanceof DataUpdate && $options['transactionTicket'] !== null ) {
+                       if ( $options['defer'] === false ) {
+                               if ( $options['transactionTicket'] !== null ) {
                                        $update->setTransactionTicket( $options['transactionTicket'] );
                                }
                                $update->doUpdate();
+                       } else {
+                               DeferredUpdates::addUpdate( $update, $options['defer'] );
                        }
-               } else {
-                       $cacheTime = $this->getCanonicalParserOutput()->getCacheTime();
-                       // Bundle all of the data updates into a single deferred update wrapper so that
-                       // any failure will cause at most one refreshLinks job to be enqueued by
-                       // DeferredUpdates::doUpdates(). This is hard to do when there are many separate
-                       // updates that are not defined as being related.
-                       $update = new RefreshSecondaryDataUpdate(
-                               $this->wikiPage,
-                               $updates,
-                               $options,
-                               $cacheTime,
-                               $this->loadbalancerFactory->getLocalDomainID()
-                       );
-                       $update->setRevision( $legacyRevision );
-                       $update->setTriggeringUser( $triggeringUser );
-                       DeferredUpdates::addUpdate( $update, $options['defer'] );
                }
        }
 
index a14b25c..67b5490 100644 (file)
@@ -280,16 +280,6 @@ class DeferredUpdates {
                        }
                        MWExceptionHandler::rollbackMasterChangesAndLog( $e );
 
-                       // Try to push the update as a job so it can run later perhaps
-                       if ( $mode !== 'enqueue' && $update instanceof EnqueueableDataUpdate ) {
-                               try {
-                                       $spec = $update->getAsJobSpecification();
-                                       JobQueueGroup::singleton( $spec['wiki'] )->push( $spec['job'] );
-                               } catch ( Exception $e ) {
-                                       MWExceptionHandler::rollbackMasterChangesAndLog( $e );
-                               }
-                       }
-
                        // VW-style hack to work around T190178, so we can make sure
                        // PageMetaDataUpdater doesn't throw exceptions.
                        if ( defined( 'MW_PHPUNIT_TEST' ) ) {
index 101a1e2..7a31e26 100644 (file)
@@ -32,7 +32,7 @@ use Wikimedia\ScopedCallback;
  *
  * See docs/deferred.txt
  */
-class LinksUpdate extends DataUpdate {
+class LinksUpdate extends DataUpdate implements EnqueueableDataUpdate {
        // @todo make members protected, but make sure extensions don't break
 
        /** @var int Page ID of the article linked from */
@@ -1187,4 +1187,39 @@ class LinksUpdate extends DataUpdate {
 
                return $this->db;
        }
+
+       public function getAsJobSpecification() {
+               if ( $this->user ) {
+                       $userInfo = [
+                               'userId' => $this->user->getId(),
+                               'userName' => $this->user->getName(),
+                       ];
+               } else {
+                       $userInfo = false;
+               }
+
+               if ( $this->mRevision ) {
+                       $triggeringRevisionId = $this->mRevision->getId();
+               } else {
+                       $triggeringRevisionId = false;
+               }
+
+               return [
+                       'wiki' => WikiMap::getWikiIdFromDbDomain( $this->getDB()->getDomainID() ),
+                       'job'  => new JobSpecification(
+                               'refreshLinksPrioritized',
+                               [
+                                       // Reuse the parser cache if it was saved
+                                       'rootJobTimestamp' => $this->mParserOutput->getCacheTime(),
+                                       'useRecursiveLinksUpdate' => $this->mRecursive,
+                                       'triggeringUser' => $userInfo,
+                                       'triggeringRevisionId' => $triggeringRevisionId,
+                                       'causeAction' => $this->getCauseAction(),
+                                       'causeAgent' => $this->getCauseAgent()
+                               ],
+                               [ 'removeDuplicates' => true ],
+                               $this->getTitle()
+                       )
+               ];
+       }
 }
diff --git a/includes/deferred/RefreshSecondaryDataUpdate.php b/includes/deferred/RefreshSecondaryDataUpdate.php
deleted file mode 100644 (file)
index 8086a70..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-<?php
-/**
- * Updater for secondary data after a page edit.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @file
- */
-
-/**
- * Update object handling the cleanup of secondary data after a page was edited.
- *
- * This makes makes it possible for DeferredUpdates to have retry logic using a single
- * refreshLinks job if any of the bundled updates fail.
- */
-class RefreshSecondaryDataUpdate extends DataUpdate implements EnqueueableDataUpdate {
-       /** @var WikiPage */
-       private $page;
-       /** @var DeferrableUpdate[] */
-       private $updates;
-       /** @var bool */
-       private $recursive;
-       /** @var string */
-       private $cacheTimestamp;
-       /** @var string Database domain ID */
-       private $domain;
-
-       /** @var Revision|null */
-       private $revision;
-       /** @var User|null */
-       private $user;
-
-       /**
-        * @param WikiPage $page Page we are updating
-        * @param DeferrableUpdate[] $updates Updates from DerivedPageDataUpdater::getSecondaryUpdates()
-        * @param array $options Options map (causeAction, causeAgent, recursive)
-        * @param string $cacheTime Result of ParserOutput::getCacheTime() for the source output
-        * @param string $domain The database domain ID of the wiki the update is for
-        */
-       function __construct(
-               WikiPage $page,
-               array $updates,
-               array $options,
-               $cacheTime,
-               $domain
-       ) {
-               parent::__construct();
-
-               $this->page = $page;
-               $this->updates = $updates;
-               $this->causeAction = $options['causeAction'] ?? 'unknown';
-               $this->causeAgent = $options['causeAgent'] ?? 'unknown';
-               $this->recursive = !empty( $options['recursive'] );
-               $this->cacheTimestamp = $cacheTime;
-               $this->domain = $domain;
-       }
-
-       public function doUpdate() {
-               foreach ( $this->updates as $update ) {
-                       $update->doUpdate();
-               }
-       }
-
-       /**
-        * Set the revision corresponding to this LinksUpdate
-        * @param Revision $revision
-        */
-       public function setRevision( Revision $revision ) {
-               $this->revision = $revision;
-       }
-
-       /**
-        * Set the User who triggered this LinksUpdate
-        * @param User $user
-        */
-       public function setTriggeringUser( User $user ) {
-               $this->user = $user;
-       }
-
-       public function getAsJobSpecification() {
-               return [
-                       'wiki' => WikiMap::getWikiIdFromDomain( $this->domain ),
-                       'job'  => new JobSpecification(
-                               'refreshLinksPrioritized',
-                               [
-                                       // Reuse the parser cache if it was saved
-                                       'rootJobTimestamp' => $this->cacheTimestamp,
-                                       'useRecursiveLinksUpdate' => $this->recursive,
-                                       'triggeringUser' => $this->user
-                                               ? [
-                                                       'userId' => $this->user->getId(),
-                                                       'userName' => $this->user->getName()
-                                               ]
-                                               : false,
-                                       'triggeringRevisionId' => $this->revision ? $this->revision->getId() : false,
-                                       'causeAction' => $this->getCauseAction(),
-                                       'causeAgent' => $this->getCauseAgent()
-                               ],
-                               [ 'removeDuplicates' => true ],
-                               $this->page->getTitle()
-                       )
-               ];
-       }
-}