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
This commit is contained in:
Jason Linehan 2018-11-15 11:02:32 -05:00 committed by Krinkle
parent 29129160af
commit aed6be47ac
2 changed files with 7 additions and 4 deletions

View 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;
}

View 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 );