Index: trunk/extensions/LiquidThreads/classes/LqtThread.php |
— | — | @@ -50,6 +50,8 @@ |
51 | 51 | protected $double; |
52 | 52 | |
53 | 53 | protected $replies; |
| 54 | + |
| 55 | + static $titleCacheById = array(); |
54 | 56 | |
55 | 57 | function isHistorical() { |
56 | 58 | return false; |
— | — | @@ -314,7 +316,11 @@ |
315 | 317 | $this->root = new Post( $root_title ); |
316 | 318 | $this->root->loadPageData( $line ); |
317 | 319 | } 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 | + } |
319 | 325 | $this->root = new Post( $root_title ); |
320 | 326 | } |
321 | 327 | |
— | — | @@ -327,7 +333,31 @@ |
328 | 334 | static function bulkLoad( $rows ) { |
329 | 335 | $threads = array(); |
330 | 336 | |
| 337 | + // Preload page data in one swoop. |
| 338 | + $pageIds = array(); |
| 339 | + |
331 | 340 | 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 ) { |
332 | 362 | $threads[] = new Thread( $row, null ); |
333 | 363 | } |
334 | 364 | |