Made replaceSectionContent try to use DB_SLAVE
authorAaron Schulz <aschulz@wikimedia.org>
Mon, 6 Apr 2015 23:22:10 +0000 (16:22 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Mon, 6 Apr 2015 23:22:10 +0000 (16:22 -0700)
Bug: T92357
Change-Id: I1626280c863a46d49215cc384e207458b2f8ec39

includes/page/WikiPage.php

index b435c5c..eb8532f 100644 (file)
@@ -1513,8 +1513,18 @@ class WikiPage implements Page, IDBAccessObject {
 
                $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();
                        }