Made LinksUpdate on edit use the job queue
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 30 Sep 2015 19:30:22 +0000 (12:30 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 8 Oct 2015 08:02:03 +0000 (01:02 -0700)
* LinksUpdate is now an EnqueueableDataUpdate
  and can yeild a prioritzed refreshLinks job.
* DeferredUpdates::runUpdates() now takes an enqueue
  flag to try to use jobs. This is set in restInPeace().
  Updates that change many links will be less likely to
  increase lag, as the runners are more strict about that.
* Also made the LinksDeletionUpdate job enqueue happen
  post-send on page deletion for consistency

Bug: T95501
Change-Id: I8863caef9c8f03234699d33e4d47d2310a0c8446

includes/MediaWiki.php
includes/deferred/DeferredUpdates.php
includes/deferred/LinksUpdate.php
includes/page/WikiPage.php

index 418ed8b..aee6ee1 100644 (file)
@@ -690,7 +690,7 @@ class MediaWiki {
                Profiler::instance()->getTransactionProfiler()->resetExpectations();
 
                // Do any deferred jobs
-               DeferredUpdates::doUpdates( 'commit' );
+               DeferredUpdates::doUpdates( 'commit', 'enqueue' );
 
                // Make sure any lazy jobs are pushed
                JobQueueGroup::pushLazyJobs();
index 8b3582d..53312cd 100644 (file)
@@ -95,9 +95,10 @@ class DeferredUpdates {
         * Do any deferred updates and clear the list
         *
         * @param string $commit Set to 'commit' to commit after every update to
+        * @param string $mode Use "enqueue" to use the job queue when possible [Default: run]
         *   prevent lock contention
         */
-       public static function doUpdates( $commit = '' ) {
+       public static function doUpdates( $commit = '', $mode = 'run' ) {
                $updates = self::$updates;
 
                while ( count( $updates ) ) {
@@ -115,12 +116,11 @@ class DeferredUpdates {
                        }
 
                        // Delegate DataUpdate execution to the DataUpdate class
-                       DataUpdate::runUpdates( $dataUpdates, 'run' );
+                       DataUpdate::runUpdates( $dataUpdates, $mode );
                        // Execute the non-DataUpdate tasks
                        foreach ( $otherUpdates as $update ) {
                                try {
                                        $update->doUpdate();
-
                                        if ( $commit === 'commit' ) {
                                                wfGetLBFactory()->commitMasterChanges();
                                        }
index be5aff3..d996870 100644 (file)
@@ -25,7 +25,7 @@
  *
  * @todo document (e.g. one-sentence top-level class description).
  */
-class LinksUpdate extends SqlDataUpdate {
+class LinksUpdate extends SqlDataUpdate implements EnqueueableDataUpdate {
        // @todo make members protected, but make sure extensions don't break
 
        /** @var int Page ID of the article linked from */
@@ -934,4 +934,16 @@ class LinksUpdate extends SqlDataUpdate {
                        );
                }
        }
+
+       public function getAsJobSpecification() {
+               return array(
+                       'wiki' => $this->mDb->getWikiID(),
+                       'job'  => new JobSpecification(
+                               'refreshLinks',
+                               array( 'prioritize' => true ),
+                               array( 'removeDuplicates' => true ),
+                               $this->getTitle()
+                       )
+               );
+       }
 }
index e47e06c..1ded678 100644 (file)
@@ -2935,10 +2935,9 @@ class WikiPage implements Page, IDBAccessObject {
 
                // Delete pagelinks, update secondary indexes, etc
                $updates = $this->getDeletionUpdates( $content );
-               // Make sure an enqueued jobs run after commit so they see the deletion
-               wfGetDB( DB_MASTER )->onTransactionIdle( function() use ( $updates ) {
-                       DataUpdate::runUpdates( $updates, 'enqueue' );
-               } );
+               foreach ( $updates as $update ) {
+                       DeferredUpdates::addUpdate( $update );
+               }
 
                // Reparse any pages transcluding this page
                LinksUpdate::queueRecursiveJobsForTable( $this->mTitle, 'templatelinks' );