r54531 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54530‎ | r54531 | r54532 >
Date:16:39, 6 August 2009
Author:werdna
Status:deferred
Tags:
Comment:
LiquidThreads performance (query consolidation) updates.
* Cache article objects by ID in bulkLoad, to prevent a million queries from loading them individually.
* Make sure all created article objects have the LQT compatibility layer, so that the data isn't thrown away to add the compat layer later.
* Fix reply preloading in bulkLoad (previously had no negative caching).
* Link-batch the user and user talk pages in bulkLoad, they will be required to display the threads (signature portion).
* Precache page restriction data in bulkLoad.
* Expand allowed size for thread title cache from 1k to 10k.
* Add user IDs to User object cache.
Modified paths:
  • /trunk/extensions/LiquidThreads/classes/Thread.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/classes/Thread.php
@@ -53,6 +53,7 @@
5454
5555 static $titleCacheById = array();
5656 static $replyCacheById = array();
 57+ static $articleCacheById = array();
5758
5859 function isHistorical() {
5960 return false;
@@ -272,12 +273,12 @@
273274 $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $this->title()->getPrefixedText() . "]]\n";
274275
275276 // Make the article edit.
276 - $traceTitle = Threads::newThreadTitle( $this->subject(), new Article($oldTitle) );
277 - $redirectArticle = new Article( $traceTitle );
 277+ $traceTitle = Threads::newThreadTitle( $this->subject(), new Article_LQT_Compat($oldTitle) );
 278+ $redirectArticle = new Article_LQT_Compat( $traceTitle );
278279 $redirectArticle->doEdit( $redirectText, $reason, EDIT_NEW );
279280
280281 // Add the trace thread to the tracking table.
281 - $thread = Threads::newThread( $redirectArticle, new Article($oldTitle), null,
 282+ $thread = Threads::newThread( $redirectArticle, new Article_LQT_Compat($oldTitle), null,
282283 Threads::TYPE_MOVED, $this->subject() );
283284 }
284285
@@ -317,7 +318,7 @@
318319
319320 if ( isset($line->page_namespace) && isset($line->page_title) ) {
320321 $root_title = Title::makeTitle( $line->page_namespace, $line->page_title );
321 - $this->root = new Article( $root_title );
 322+ $this->root = new Article_LQT_Compat( $root_title );
322323 $this->root->loadPageData( $line );
323324 } else {
324325 if ( isset( self::$titleCacheById[$this->rootId] ) ) {
@@ -327,7 +328,7 @@
328329 }
329330
330331 if ($root_title) {
331 - $this->root = new Article( $root_title );
 332+ $this->root = new Article_LQT_Compat( $root_title );
332333 $this->rootRevision = $this->root->mLatest;
333334 }
334335 }
@@ -340,6 +341,7 @@
341342 // Preload subthreads
342343 $thread_ids = array();
343344 $pageIds = array();
 345+ $linkBatch = new LinkBatch();
344346
345347 if (!is_array(self::$replyCacheById)) {
346348 self::$replyCacheById = array();
@@ -353,6 +355,10 @@
354356 $pageIds[] = $row->thread_root;
355357 if ($row->thread_summary_page)
356358 $pageIds[] = $row->thread_summary_page;
 359+
 360+ if ( !isset( self::$replyCacheById[$row->thread_id] ) ) {
 361+ self::$replyCacheById[$row->thread_id] = array();
 362+ }
357363 }
358364
359365 if ( count($thread_ids) ) {
@@ -362,31 +368,47 @@
363369
364370 while( $row = $dbr->fetchObject($res) ) {
365371 // Grab page data while we're here.
 372+ $rows[] = $row;
366373 if ($row->thread_root)
367374 $pageIds[] = $row->thread_root;
368375 if ($row->thread_summary_page)
369376 $pageIds[] = $row->thread_summary_page;
370 -
371 - if ( !is_null($row->thread_parent) ) {
372 - if ( !isset( self::$replyCacheById[$row->thread_parent] ) ) {
373 - self::$replyCacheById[$row->thread_parent] = array();
374 - }
375377
376 - self::$replyCacheById[$row->thread_parent][$row->thread_id] =
377 - new Thread( $row, null );
 378+ if ( !isset( self::$replyCacheById[$row->thread_id] ) ) {
 379+ self::$replyCacheById[$row->thread_id] = array();
378380 }
379381 }
380382 }
381383
382384 // Preload page data in one swoop.
 385+ $articlesById = array();
383386 if ( count($pageIds) ) {
 387+ // Pull restriction info. Needs to come first because otherwise it's done per
 388+ // page by loadPageData.
 389+ $restrictionRows = array_fill_keys( $pageIds, array() );
 390+ $res = $dbr->select( 'page_restrictions', '*', array( 'pr_page' => $pageIds ),
 391+ __METHOD__ );
 392+ while( $row = $dbr->fetchObject( $res ) ) {
 393+ $restrictionRows[$row->pr_page][] = $row;
 394+ }
 395+
384396 $res = $dbr->select( 'page', '*', array( 'page_id' => $pageIds ), __METHOD__ );
 397+
385398 while( $row = $dbr->fetchObject( $res ) ) {
386399 $t = Title::newFromRow( $row );
387400
 401+ if ( isset( $restrictionRows[$t->getArticleId()] ) ) {
 402+ $t->loadRestrictionsFromRows( $restrictionRows[$t->getArticleId()],
 403+ $row->page_restrictions );
 404+ }
 405+
 406+ $article = new Article_LQT_Compat( $t );
 407+ $article->loadPageData( $row );
 408+
388409 self::$titleCacheById[$t->getArticleId()] = $t;
 410+ $articlesById[$article->getId()] = $article;
389411
390 - if ( count(self::$titleCacheById) > 1000 ) {
 412+ if ( count(self::$titleCacheById) > 10000 ) {
391413 self::$titleCacheById = array();
392414 }
393415 }
@@ -395,10 +417,25 @@
396418 $threads = array();
397419
398420 foreach( $rows as $row ) {
399 - $threads[] = $thread = new Thread( $row, null );
 421+ $threads[$row->thread_id] = $thread = new Thread( $row, null );
 422+ $thread->root = $articlesById[$thread->rootId];
400423 Threads::$cache_by_id[$row->thread_id] = $thread;
 424+
 425+ // User cache data
 426+ $t = Title::makeTitleSafe( NS_USER, $row->thread_author_name );
 427+ $linkBatch->addObj( $t );
 428+ $t = Title::makeTitleSafe( NS_USER_TALK, $row->thread_author_name );
 429+ $linkBatch->addObj( $t );
 430+
 431+ User::$idCacheByName[$row->thread_author_name] = $row->thread_author_id;
 432+
 433+ if ( $row->thread_parent ) {
 434+ self::$replyCacheById[$row->thread_parent][$row->thread_id] = $thread;
 435+ }
401436 }
402437
 438+ $linkBatch->execute();
 439+
403440 return $threads;
404441 }
405442
@@ -488,7 +525,7 @@
489526 LqtDispatch::isLqtPage( $articleTitle->getTalkPage() ) &&
490527 $articleTitle->getNamespace() != NS_LQT_THREAD ) {
491528 $newTitle = $articleTitle->getTalkPage();
492 - $newArticle = new Article( $newTitle );
 529+ $newArticle = new Article_LQT_Compat( $newTitle );
493530
494531 $set['thread_article_namespace'] = $newTitle->getNamespace();
495532 $set['thread_article_title'] = $newTitle->getDbKey();
@@ -672,7 +709,7 @@
673710 if ( !is_null( $this->articleId ) ) {
674711 $title = Title::newFromID( $this->articleId );
675712 if ( $title ) {
676 - $article = new Article( $title );
 713+ $article = new Article_LQT_Compat( $title );
677714 }
678715 }
679716 if ( isset( $article ) && $article->exists() ) {
@@ -680,7 +717,7 @@
681718 return $article;
682719 } else {
683720 $title = Title::makeTitle( $this->articleNamespace, $this->articleTitle );
684 - return new Article( $title );
 721+ return new Article_LQT_Compat( $title );
685722 }
686723 }
687724
@@ -696,10 +733,20 @@
697734 function root() {
698735 if ( !$this->rootId ) return null;
699736 if ( !$this->root ) {
700 - $title = Title::newFromID( $this->rootId );
 737+ if ( isset(self::$articleCacheById[$this->rootId]) ) {
 738+ $this->root = self::$articleCacheById[$this->rootId];
 739+ return $this->root;
 740+ }
 741+
 742+ if ( isset( self::$titleCacheById[$this->rootId] ) ) {
 743+ $title = self::$titleCacheById[$this->rootId];
 744+ } else {
 745+ $title = Title::newFromID( $this->rootId );
 746+ }
 747+
701748 if (!$title) return null;
702749
703 - $this->root = new Article( $title, $this->rootRevision() );
 750+ $this->root = new Article_LQT_Compat( $title, $this->rootRevision() );
704751 }
705752 return $this->root;
706753 }
@@ -733,7 +780,7 @@
734781 return null;
735782 }
736783
737 - $this->summary = new Article( $title );
 784+ $this->summary = new Article_LQT_Compat( $title );
738785
739786 }
740787
@@ -857,7 +904,7 @@
858905 $rev = Revision::newFromId( $this->root()->getLatest() );
859906 $rtitle = Title::newFromRedirect( $rev->getRawText() );
860907 if ( !$rtitle ) return null;
861 - $rthread = Threads::withRoot( new Article( $rtitle ) );
 908+ $rthread = Threads::withRoot( new Article_LQT_Compat( $rtitle ) );
862909 return $rthread;
863910 }
864911

Status & tagging log