r53181 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53180‎ | r53181 | r53182 >
Date:17:20, 13 July 2009
Author:werdna
Status:deferred
Tags:
Comment:
Fix for bulk thread loading:
* Something funky was going on with array_merge(), now fixed.
* Prevent duplicate entries confusing it by keying with the reply's id.
Modified paths:
  • /trunk/extensions/LiquidThreads/classes/LqtThread.php (modified) (history)
  • /trunk/extensions/LiquidThreads/pages/TalkpageView.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/pages/TalkpageView.php
@@ -30,18 +30,16 @@
3131 $sk = $wgUser->getSkin();
3232
3333 $article = new Article( $this->title );
34 - $revision = Revision::newFromId( $article->getLatest() );
35 - if ( $revision ) $article_text = $revision->getRawText();
3634
3735 $oldid = $this->request->getVal( 'oldid', null );
3836
3937 wfLoadExtensionMessages( 'LiquidThreads' );
4038 // If $article_text == "", the talkpage was probably just created
4139 // when the first thread was posted to make the links blue.
42 - if ( $article->exists() && $article_text != "" ) {
 40+ if ( $article->exists() && $article->getContent() ) {
4341 $html = '';
4442
45 - $html .= $this->showPostBody( $article, $oldid );
 43+ $article->view();
4644
4745 $actionLinks = array();
4846 $actionLinks[] = $sk->link( $this->title,
Index: trunk/extensions/LiquidThreads/classes/LqtThread.php
@@ -339,8 +339,11 @@
340340 // Preload subthreads
341341 $thread_ids = array();
342342 $pageIds = array();
343 - $replies_by_id = array();
344343
 344+ if (!is_array(self::$replyCacheById)) {
 345+ self::$replyCacheById = array();
 346+ }
 347+
345348 foreach( $rows as $row ) {
346349 $thread_ids[] = $row->thread_id;
347350
@@ -363,16 +366,17 @@
364367 if ($row->thread_summary_page)
365368 $pageIds[] = $row->thread_summary_page;
366369
367 - if (!isset( $replies_by_id[$row->thread_parent] ) ) {
368 - $replies_by_id[$row->thread_parent] = array();
 370+ if ( !is_null($row->thread_parent) ) {
 371+ if ( !isset( self::$replyCacheById[$row->thread_parent] ) ) {
 372+ self::$replyCacheById[$row->thread_parent] = array();
 373+ }
 374+
 375+ self::$replyCacheById[$row->thread_parent][$row->thread_id] =
 376+ new Thread( $row, null );
369377 }
370 -
371 - $replies_by_id[$row->thread_parent][] = new Thread( $row, null );
372378 }
373379 }
374380
375 - self::$replyCacheById = array_merge( self::$replyCacheById, $replies_by_id );
376 -
377381 // Preload page data in one swoop.
378382 if ( count($pageIds) ) {
379383 $res = $dbr->select( 'page', '*', array( 'page_id' => $pageIds ), __METHOD__ );
@@ -544,6 +548,7 @@
545549 return false;
546550 }
547551 }
 552+
548553 function replies() {
549554 if ( !is_null($this->replies) ) {
550555 return $this->replies;
@@ -551,8 +556,7 @@
552557
553558 // Check cache
554559 if ( isset( self::$replyCacheById[$this->id()] ) ) {
555 - $this->replies = self::$replyCacheById[$this->id()];
556 - return $this->replies;
 560+ return self::$replyCacheById[$this->id()];
557561 }
558562
559563 $this->replies = array();

Status & tagging log