From 4a279515f4f670112aeaa26d9c8d5c44ee358020 Mon Sep 17 00:00:00 2001 From: umherirrender Date: Sun, 27 May 2012 16:39:04 +0200 Subject: [PATCH] Revision::getTitle produce rev_id IS NULL query Seen on Special:NewPages: Linker::revComment is calling Revision::getTitle, but the revision object has no id set. This is another way to avoid a query per non-empty comment on Special:NewPages, see gerrit 9003 Change-Id: I1786a4c13000f574c0f34fb59759bb2fc4117bcd --- includes/Revision.php | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/includes/Revision.php b/includes/Revision.php index 6928eb97f6..fa2e7b3d01 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -493,7 +493,7 @@ class Revision { /** * Get revision ID * - * @return Integer + * @return Integer|null */ public function getId() { return $this->mId; @@ -512,7 +512,7 @@ class Revision { /** * Get text row ID * - * @return Integer + * @return Integer|null */ public function getTextId() { return $this->mTextId; @@ -530,7 +530,7 @@ class Revision { /** * Returns the length of the text in this revision, or null if unknown. * - * @return Integer + * @return Integer|null */ public function getSize() { return $this->mSize; @@ -539,30 +539,34 @@ class Revision { /** * Returns the base36 sha1 of the text in this revision, or null if unknown. * - * @return String + * @return String|null */ public function getSha1() { return $this->mSha1; } /** - * Returns the title of the page associated with this entry. + * Returns the title of the page associated with this entry or null. * - * @return Title + * Will do a query, when title is not set and id is given. + * + * @return Title|null */ public function getTitle() { if( isset( $this->mTitle ) ) { return $this->mTitle; } - $dbr = wfGetDB( DB_SLAVE ); - $row = $dbr->selectRow( - array( 'page', 'revision' ), - self::selectPageFields(), - array( 'page_id=rev_page', - 'rev_id' => $this->mId ), - __METHOD__ ); - if ( $row ) { - $this->mTitle = Title::newFromRow( $row ); + if( !is_null( $this->mId ) ) { //rev_id is defined as NOT NULL + $dbr = wfGetDB( DB_SLAVE ); + $row = $dbr->selectRow( + array( 'page', 'revision' ), + self::selectPageFields(), + array( 'page_id=rev_page', + 'rev_id' => $this->mId ), + __METHOD__ ); + if ( $row ) { + $this->mTitle = Title::newFromRow( $row ); + } } return $this->mTitle; } @@ -579,7 +583,7 @@ class Revision { /** * Get the page ID * - * @return Integer + * @return Integer|null */ public function getPage() { return $this->mPage; -- 2.20.1