r106523 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106522‎ | r106523 | r106524 >
Date:19:55, 17 December 2011
Author:reedy
Status:reverted (Comments)
Tags:
Comment:
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
Modified paths:
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryBase.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryBase.php
@@ -304,7 +304,11 @@
305305 */
306306 public static function addTitleInfo( &$arr, $title, $prefix = '' ) {
307307 $arr[$prefix . 'ns'] = intval( $title->getNamespace() );
308 - $arr[$prefix . 'pageid'] = $title->getArticleID();
 308+ // TODO: This is a workaround for bug 28901, as the Article ID isn't always loaded
 309+ // Saves many DB queries, but does need cleaning up, so callers have always loaded the Article ID also
 310+ if ( $title->isArticleIDLoaded() ) {
 311+ $arr[$prefix . 'pageid'] = $title->getArticleID();
 312+ }
309313 $arr[$prefix . 'title'] = $title->getPrefixedText();
310314 }
311315
Index: trunk/phase3/includes/Title.php
@@ -2808,6 +2808,15 @@
28092809 }
28102810
28112811 /**
 2812+ * Returns a bool to say whether the Article ID for this title has already been loaded
 2813+ *
 2814+ * @return bool
 2815+ */
 2816+ public function isArticleIDLoaded() {
 2817+ return $this->mArticleID != -1;
 2818+ }
 2819+
 2820+ /**
28122821 * Get the article ID for this Title from the link cache,
28132822 * adding it if necessary
28142823 *
@@ -2825,10 +2834,8 @@
28262835 $linkCache->clearLink( $this );
28272836 $this->mArticleID = $linkCache->addLinkObj( $this );
28282837 $linkCache->forUpdate( $oldUpdate );
2829 - } else {
2830 - if ( -1 == $this->mArticleID ) {
2831 - $this->mArticleID = $linkCache->addLinkObj( $this );
2832 - }
 2838+ } else if ( -1 == $this->mArticleID ) {
 2839+ $this->mArticleID = $linkCache->addLinkObj( $this );
28332840 }
28342841 return $this->mArticleID;
28352842 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r106862Revert r106523: abstraction violation, looks very wrong, unclear benefitsbrion21:20, 20 December 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r105831Make ApiQueryBase::addTitleInfo() add the pageid alsoreedy21:07, 11 December 2011

Comments

#Comment by Brion VIBBER (talk | contribs)   21:18, 20 December 2011

This is a weird abstraction violation, and I'm not really sure why you'd want to do this...

#Comment by Brion VIBBER (talk | contribs)   21:21, 20 December 2011

Reverted in r106862.

#Comment by Reedy (talk | contribs)   21:22, 20 December 2011
This does not work very well with all modules, which are using this function. For example list=allimages. Maybe set the pageid only, when it is set in $title or add LinkBatches to that module or change the query to join the page table also for grapping the pageid.
Please check all modules to avoid hugh load on the server.

on r105831

#Comment by Brion VIBBER (talk | contribs)   21:38, 20 December 2011

Thanks, reverted that too until a proper fix is in place.

#Comment by Reedy (talk | contribs)   21:47, 20 December 2011

Right, that makes a little bit more sense then :p

Status & tagging log