From aed6be47ac2764c1cebce39bd1c771808fa23a06 Mon Sep 17 00:00:00 2001 From: Jason Linehan Date: Thu, 15 Nov 2018 11:02:32 -0500 Subject: [PATCH] Fully utilize LinkTarget passed to getRevisionByTitle 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 | 10 ++++++---- tests/phpunit/includes/api/ApiMoveTest.php | 1 + 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/includes/Revision/RevisionStore.php b/includes/Revision/RevisionStore.php index 7dd4eead17..9af2458047 100644 --- a/includes/Revision/RevisionStore.php +++ b/includes/Revision/RevisionStore.php @@ -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; } diff --git a/tests/phpunit/includes/api/ApiMoveTest.php b/tests/phpunit/includes/api/ApiMoveTest.php index b9c49b11b4..d437a525a0 100644 --- a/tests/phpunit/includes/api/ApiMoveTest.php +++ b/tests/phpunit/includes/api/ApiMoveTest.php @@ -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 ); -- 2.20.1