Merge "Made replaceSectionContent try to use DB_SLAVE"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 7 Apr 2015 09:29:54 +0000 (09:29 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 7 Apr 2015 09:29:54 +0000 (09:29 +0000)
1  2 
includes/page/WikiPage.php

@@@ -1513,8 -1513,18 +1513,18 @@@ class WikiPage implements Page, IDBAcce
  
                $baseRevId = null;
                if ( $edittime && $sectionId !== 'new' ) {
-                       $dbw = wfGetDB( DB_MASTER );
-                       $rev = Revision::loadFromTimestamp( $dbw, $this->mTitle, $edittime );
+                       $dbr = wfGetDB( DB_SLAVE );
+                       $rev = Revision::loadFromTimestamp( $dbr, $this->mTitle, $edittime );
+                       // Try the master if this thread may have just added it.
+                       // This could be abstracted into a Revision method, but we don't want
+                       // to encourage loading of revisions by timestamp.
+                       if ( !$rev
+                               && wfGetLB()->getServerCount() > 1
+                               && wfGetLB()->hasOrMadeRecentMasterChanges()
+                       ) {
+                               $dbw = wfGetDB( DB_MASTER );
+                               $rev = Revision::loadFromTimestamp( $dbw, $this->mTitle, $edittime );
+                       }
                        if ( $rev ) {
                                $baseRevId = $rev->getId();
                        }
                        if ( is_null( $baseRevId ) || $sectionId === 'new' ) {
                                $oldContent = $this->getContent();
                        } else {
 -                              // TODO: try DB_SLAVE first
 -                              $dbw = wfGetDB( DB_MASTER );
 -                              $rev = Revision::loadFromId( $dbw, $baseRevId );
 -
 +                              $rev = Revision::newFromId( $baseRevId );
                                if ( !$rev ) {
                                        wfDebug( __METHOD__ . " asked for bogus section (page: " .
                                                $this->getId() . "; section: $sectionId)\n" );