From 997fb135cdf3d27afb77e91dc6b962ce255d34d7 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Sat, 17 Dec 2011 19:55:49 +0000 Subject: [PATCH] Per bug 28901, and Duplicatebug on r105831, only list the Article ID if it has already been loaded Not a long term fix, but saves potentially a lot of database queries to lookup article ids, until the other issues on bug 28901 are tidied up --- includes/Title.php | 15 +++++++++++---- includes/api/ApiQueryBase.php | 6 +++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index aa96b95890..6dd79d24c7 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -2807,6 +2807,15 @@ class Title { return $this->mCounter; } + /** + * Returns a bool to say whether the Article ID for this title has already been loaded + * + * @return bool + */ + public function isArticleIDLoaded() { + return $this->mArticleID != -1; + } + /** * Get the article ID for this Title from the link cache, * adding it if necessary @@ -2825,10 +2834,8 @@ class Title { $linkCache->clearLink( $this ); $this->mArticleID = $linkCache->addLinkObj( $this ); $linkCache->forUpdate( $oldUpdate ); - } else { - if ( -1 == $this->mArticleID ) { - $this->mArticleID = $linkCache->addLinkObj( $this ); - } + } else if ( -1 == $this->mArticleID ) { + $this->mArticleID = $linkCache->addLinkObj( $this ); } return $this->mArticleID; } diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index e3cf51f50c..fdaa630abc 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -304,7 +304,11 @@ abstract class ApiQueryBase extends ApiBase { */ public static function addTitleInfo( &$arr, $title, $prefix = '' ) { $arr[$prefix . 'ns'] = intval( $title->getNamespace() ); - $arr[$prefix . 'pageid'] = $title->getArticleID(); + // TODO: This is a workaround for bug 28901, as the Article ID isn't always loaded + // Saves many DB queries, but does need cleaning up, so callers have always loaded the Article ID also + if ( $title->isArticleIDLoaded() ) { + $arr[$prefix . 'pageid'] = $title->getArticleID(); + } $arr[$prefix . 'title'] = $title->getPrefixedText(); } -- 2.20.1