Implement WikiPage::getOldestRevision() in terms of Title::getFirstRevision()
authorRoan Kattouw <roan.kattouw@gmail.com>
Wed, 29 Mar 2017 15:53:08 +0000 (11:53 -0400)
committerRoan Kattouw <roan.kattouw@gmail.com>
Wed, 29 Mar 2017 15:53:08 +0000 (11:53 -0400)
They were both doing the same thing, except that getOldestRevision()
checks the master if the revision is missing on the replica.

Change-Id: I21a118c6cd5c98fb846a0a2765574c0dbdbf7220

includes/Title.php
includes/page/WikiPage.php

index 0c5835c..f8d973c 100644 (file)
@@ -4030,7 +4030,6 @@ class Title implements LinkTarget {
                                __METHOD__,
                                [
                                        'ORDER BY' => 'rev_timestamp ASC',
-                                       'LIMIT' => 1,
                                        'IGNORE INDEX' => 'rev_timestamp'
                                ]
                        );
index 1d5973b..6d2cdeb 100644 (file)
@@ -574,36 +574,12 @@ class WikiPage implements Page, IDBAccessObject {
         * @return Revision|null
         */
        public function getOldestRevision() {
-
                // Try using the replica DB first, then try the master
-               $continue = 2;
-               $db = wfGetDB( DB_REPLICA );
-               $revSelectFields = Revision::selectFields();
-
-               $row = null;
-               while ( $continue ) {
-                       $row = $db->selectRow(
-                               [ 'revision' ],
-                               $revSelectFields,
-                               [
-                                       'rev_page' => $this->getId()
-                               ],
-                               __METHOD__,
-                               [
-                                       'ORDER BY' => 'rev_timestamp ASC',
-                                       'IGNORE INDEX' => 'rev_timestamp'
-                               ]
-                       );
-
-                       if ( $row ) {
-                               $continue = 0;
-                       } else {
-                               $db = wfGetDB( DB_MASTER );
-                               $continue--;
-                       }
+               $rev = $this->mTitle->getFirstRevision();
+               if ( !$rev ) {
+                       $rev = $this->mTitle->getFirstRevision( Title::GAID_FOR_UPDATE );
                }
-
-               return $row ? Revision::newFromRow( $row ) : null;
+               return $rev;
        }
 
        /**