Avoid master queries in Revision::newFromTitle(..., Revision::READ_NORMAL)
authorTim Starling <tstarling@wikimedia.org>
Fri, 7 Jun 2013 00:31:37 +0000 (10:31 +1000)
committerTim Starling <tstarling@wikimedia.org>
Wed, 23 Oct 2013 00:22:50 +0000 (00:22 +0000)
The fallback to master makes sense in Revision::newFromId(), since a
revision ID known to exist by some other means might be present in the
master but not in the slave. But it doesn't make sense for
Revision::newFromTitle(), where by far the most common cause of this
case being hit is the page being nonexistent.

Change-Id: I41189fcde1b8065ac134982241376d63b78732a1

includes/Revision.php

index 305c8ff..233eac0 100644 (file)
@@ -116,11 +116,13 @@ class Revision implements IDBAccessObject {
                if ( $id ) {
                        // Use the specified ID
                        $conds['rev_id'] = $id;
+                       return self::newFromConds( $conds, (int)$flags );
                } else {
                        // Use a join to get the latest revision
                        $conds[] = 'rev_id=page_latest';
+                       $db = wfGetDB( ( $flags & self::READ_LATEST ) ? DB_MASTER : DB_SLAVE );
+                       return self::loadFromConds( $db, $conds, $flags );
                }
-               return self::newFromConds( $conds, (int)$flags );
        }
 
        /**