Fully utilize LinkTarget passed to getRevisionByTitle
authorJason Linehan <jlinehan@wikimedia.org>
Thu, 15 Nov 2018 16:02:32 +0000 (11:02 -0500)
committerKrinkle <krinklemail@gmail.com>
Tue, 2 Apr 2019 21:25:45 +0000 (21:25 +0000)
Failure of getRevisionByTitle to pass its LinkTarget argument
to newRevisionFromRow resulted in a needless second instantiation
of the Title (an extra query).

Because newRevisionFromRow needs a Title, not just a LinkTarget,
it is unfortunately necessary to call Title::newFromLinkTarget
on it for now -- however this does not involve a DB lookup and
is on track to be fixed with revisions to the Title class.

Bug: T206498
Change-Id: Ic6f98d8fbf66d85121668571c17e148efc5ec2be

includes/Revision/RevisionStore.php
tests/phpunit/includes/api/ApiMoveTest.php

index 7dd4eea..9af2458 100644 (file)
@@ -1508,9 +1508,11 @@ class RevisionStore
         * @return RevisionRecord|null
         */
        public function getRevisionByTitle( LinkTarget $linkTarget, $revId = 0, $flags = 0 ) {
+               // TODO should not require Title in future (T206498)
+               $title = Title::newFromLinkTarget( $linkTarget );
                $conds = [
-                       'page_namespace' => $linkTarget->getNamespace(),
-                       'page_title' => $linkTarget->getDBkey()
+                       'page_namespace' => $title->getNamespace(),
+                       'page_title' => $title->getDBkey()
                ];
                if ( $revId ) {
                        // Use the specified revision ID.
@@ -1519,7 +1521,7 @@ class RevisionStore
                        // Since the caller supplied a revision ID, we are pretty sure the revision is
                        // supposed to exist, so we should try hard to find it.
                        $conds['rev_id'] = $revId;
-                       return $this->newRevisionFromConds( $conds, $flags );
+                       return $this->newRevisionFromConds( $conds, $flags, $title );
                } else {
                        // Use a join to get the latest revision.
                        // Note that we don't use newRevisionFromConds here because we don't want to retry
@@ -1529,7 +1531,7 @@ class RevisionStore
                        $db = $this->getDBConnectionRefForQueryFlags( $flags );
 
                        $conds[] = 'rev_id=page_latest';
-                       $rev = $this->loadRevisionFromConds( $db, $conds, $flags );
+                       $rev = $this->loadRevisionFromConds( $db, $conds, $flags, $title );
 
                        return $rev;
                }
index b9c49b1..d437a52 100644 (file)
@@ -17,6 +17,7 @@ class ApiMoveTest extends ApiTestCase {
        protected function assertMoved( $from, $to, $id, $opts = null ) {
                $opts = (array)$opts;
 
+               Title::clearCaches();
                $fromTitle = Title::newFromText( $from );
                $toTitle = Title::newFromText( $to );