Merge "Avoid master queries when old filter checks are viewed"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 26 Jan 2017 17:46:24 +0000 (17:46 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 26 Jan 2017 17:46:24 +0000 (17:46 +0000)
1  2 
includes/page/WikiPage.php

@@@ -1504,6 -1504,68 +1504,6 @@@ class WikiPage implements Page, IDBAcce
                return $flags;
        }
  
 -      /**
 -       * Change an existing article or create a new article. Updates RC and all necessary caches,
 -       * optionally via the deferred update array.
 -       *
 -       * @param string $text New text
 -       * @param string $summary Edit summary
 -       * @param int $flags Bitfield:
 -       *      EDIT_NEW
 -       *          Article is known or assumed to be non-existent, create a new one
 -       *      EDIT_UPDATE
 -       *          Article is known or assumed to be pre-existing, update it
 -       *      EDIT_MINOR
 -       *          Mark this edit minor, if the user is allowed to do so
 -       *      EDIT_SUPPRESS_RC
 -       *          Do not log the change in recentchanges
 -       *      EDIT_FORCE_BOT
 -       *          Mark the edit a "bot" edit regardless of user rights
 -       *      EDIT_AUTOSUMMARY
 -       *          Fill in blank summaries with generated text where possible
 -       *      EDIT_INTERNAL
 -       *          Signal that the page retrieve/save cycle happened entirely in this request.
 -       *
 -       * If neither EDIT_NEW nor EDIT_UPDATE is specified, the status of the
 -       * article will be detected. If EDIT_UPDATE is specified and the article
 -       * doesn't exist, the function will return an edit-gone-missing error. If
 -       * EDIT_NEW is specified and the article does exist, an edit-already-exists
 -       * error will be returned. These two conditions are also possible with
 -       * auto-detection due to MediaWiki's performance-optimised locking strategy.
 -       *
 -       * @param bool|int $baseRevId The revision ID this edit was based off, if any.
 -       *   This is not the parent revision ID, rather the revision ID for older
 -       *   content used as the source for a rollback, for example.
 -       * @param User $user The user doing the edit
 -       *
 -       * @throws MWException
 -       * @return Status Possible errors:
 -       *   edit-hook-aborted: The ArticleSave hook aborted the edit but didn't
 -       *     set the fatal flag of $status
 -       *   edit-gone-missing: In update mode, but the article didn't exist.
 -       *   edit-conflict: In update mode, the article changed unexpectedly.
 -       *   edit-no-change: Warning that the text was the same as before.
 -       *   edit-already-exists: In creation mode, but the article already exists.
 -       *
 -       * Extensions may define additional errors.
 -       *
 -       * $return->value will contain an associative array with members as follows:
 -       *     new: Boolean indicating if the function attempted to create a new article.
 -       *     revision: The revision object for the inserted revision, or null.
 -       *
 -       * Compatibility note: this function previously returned a boolean value
 -       * indicating success/failure
 -       *
 -       * @deprecated since 1.21: use doEditContent() instead.
 -       */
 -      public function doEdit( $text, $summary, $flags = 0, $baseRevId = false, $user = null ) {
 -              wfDeprecated( __METHOD__, '1.21' );
 -
 -              $content = ContentHandler::makeContent( $text, $this->getTitle() );
 -
 -              return $this->doEditContent( $content, $summary, $flags, $baseRevId, $user );
 -      }
 -
        /**
         * Change an existing article or create a new article. Updates RC and all necessary caches,
         * optionally via the deferred update array.
                                );
                        } else {
                                // Try to avoid a second parse if {{REVISIONID}} is used
-                               $edit->popts->setSpeculativeRevIdCallback( function () {
-                                       return 1 + (int)wfGetDB( DB_MASTER )->selectField(
+                               $dbIndex = ( $this->mDataLoadedFrom & self::READ_LATEST ) === self::READ_LATEST
+                                       ? DB_MASTER // use the best possible guess
+                                       : DB_REPLICA; // T154554
+                               $edit->popts->setSpeculativeRevIdCallback( function () use ( $dbIndex ) {
+                                       return 1 + (int)wfGetDB( $dbIndex )->selectField(
                                                'revision',
                                                'MAX(rev_id)',
                                                [],