r52459 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52458‎ | r52459 | r52460 >
Date:14:09, 26 June 2009
Author:werdna
Status:deferred
Tags:
Comment:
Query consolidation, trying to bulk-load some data to avoid querying the database five times per post.
Modified paths:
  • /trunk/extensions/LiquidThreads/classes/LqtThread.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/classes/LqtThread.php
@@ -50,6 +50,8 @@
5151 protected $double;
5252
5353 protected $replies;
 54+
 55+ static $titleCacheById = array();
5456
5557 function isHistorical() {
5658 return false;
@@ -314,7 +316,11 @@
315317 $this->root = new Post( $root_title );
316318 $this->root->loadPageData( $line );
317319 } else {
318 - $root_title = Title::newFromID( $this->rootId );
 320+ if ( isset( self::$titleCacheById[$this->rootId] ) ) {
 321+ $root_title = self::$titleCacheById[$this->rootId];
 322+ } else {
 323+ $root_title = Title::newFromID( $this->rootId );
 324+ }
319325 $this->root = new Post( $root_title );
320326 }
321327
@@ -327,7 +333,31 @@
328334 static function bulkLoad( $rows ) {
329335 $threads = array();
330336
 337+ // Preload page data in one swoop.
 338+ $pageIds = array();
 339+
331340 foreach( $rows as $row ) {
 341+ if ($row->thread_root)
 342+ $pageIds[] = $row->thread_root;
 343+ if ($row->thread_summary_page)
 344+ $pageIds[] = $row->thread_summary_page;
 345+ }
 346+
 347+ if ( count($pageIds) ) {
 348+ $dbr = wfGetDB( DB_SLAVE );
 349+ $res = $dbr->select( 'page', '*', array( 'page_id' => $pageIds ), __METHOD__ );
 350+ while( $row = $dbr->fetchObject( $res ) ) {
 351+ $t = Title::newFromRow( $row );
 352+
 353+ self::$titleCacheById[$t->getArticleId()] = $t;
 354+
 355+ if ( count(self::$titleCacheById) > 1000 ) {
 356+ self::$titleCacheById = array();
 357+ }
 358+ }
 359+ }
 360+
 361+ foreach( $rows as $row ) {
332362 $threads[] = new Thread( $row, null );
333363 }
334364

Status & tagging log