Index: branches/wmf-deployment/extensions/LiquidThreads/classes/Thread.php |
— | — | @@ -338,6 +338,21 @@ |
339 | 339 | |
340 | 340 | // Lists total reply count, including replies to replies and such |
341 | 341 | function replyCount() { |
| 342 | + // Populate reply count |
| 343 | + if ( $this->replyCount == - 1 ) { |
| 344 | + if ( $this->isTopmostThread() ) { |
| 345 | + $dbr = wfGetDB( DB_SLAVE ); |
| 346 | + |
| 347 | + $count = $dbr->selectField( 'thread', 'count(*)', |
| 348 | + array( 'thread_ancestor' => $this->id() ), __METHOD__ ); |
| 349 | + } else { |
| 350 | + $count = self::recursiveGetReplyCount( $this ); |
| 351 | + } |
| 352 | + |
| 353 | + $this->replyCount = $count; |
| 354 | + $this->save(); |
| 355 | + } |
| 356 | + |
342 | 357 | return $this->replyCount; |
343 | 358 | } |
344 | 359 | |
— | — | @@ -410,6 +425,13 @@ |
411 | 426 | } |
412 | 427 | } |
413 | 428 | |
| 429 | + Threads::$cache_by_id[$line->thread_id] = $this; |
| 430 | + if ( $line->thread_parent ) { |
| 431 | + if ( !isset( self::$replyCacheById[$line->thread_parent] ) ) |
| 432 | + self::$replyCacheById[$line->thread_parent] = array(); |
| 433 | + self::$replyCacheById[$line->thread_parent][$line->thread_id] = $this; |
| 434 | + } |
| 435 | + |
414 | 436 | $this->doLazyUpdates( $line ); |
415 | 437 | } |
416 | 438 | |
— | — | @@ -459,10 +481,6 @@ |
460 | 482 | $pageIds[] = $row->thread_summary_page; |
461 | 483 | |
462 | 484 | $all_thread_rows[] = $row; |
463 | | - |
464 | | - if ( !isset( self::$replyCacheById[$row->thread_id] ) ) { |
465 | | - self::$replyCacheById[$row->thread_id] = array(); |
466 | | - } |
467 | 485 | } |
468 | 486 | } |
469 | 487 | |
— | — | @@ -510,8 +528,6 @@ |
511 | 529 | if ( isset( $articlesById[$thread->rootId] ) ) |
512 | 530 | $thread->root = $articlesById[$thread->rootId]; |
513 | 531 | |
514 | | - Threads::$cache_by_id[$row->thread_id] = $thread; |
515 | | - |
516 | 532 | // User cache data |
517 | 533 | $t = Title::makeTitleSafe( NS_USER, $row->thread_author_name ); |
518 | 534 | $linkBatch->addObj( $t ); |
— | — | @@ -520,10 +536,6 @@ |
521 | 537 | |
522 | 538 | User::$idCacheByName[$row->thread_author_name] = $row->thread_author_id; |
523 | 539 | $userIds[$row->thread_author_id] = true; |
524 | | - |
525 | | - if ( $row->thread_parent ) { |
526 | | - self::$replyCacheById[$row->thread_parent][$row->thread_id] = $thread; |
527 | | - } |
528 | 540 | } |
529 | 541 | |
530 | 542 | $userIds = array_keys( $userIds ); |
— | — | @@ -609,6 +621,21 @@ |
610 | 622 | return null; |
611 | 623 | } |
612 | 624 | |
| 625 | + static function recursiveGetReplyCount( $thread, $level = 1 ) { |
| 626 | + if ($level > 80) { |
| 627 | + return 1; |
| 628 | + } |
| 629 | + |
| 630 | + $count = 0; |
| 631 | + |
| 632 | + foreach( $thread->replies() as $reply ) { |
| 633 | + $count++; |
| 634 | + $count += self::recursiveGetReplyCount( $reply, $level + 1 ); |
| 635 | + } |
| 636 | + |
| 637 | + return $count; |
| 638 | + } |
| 639 | + |
613 | 640 | // Lazy updates done whenever a thread is loaded. |
614 | 641 | // Much easier than running a long-running maintenance script. |
615 | 642 | function doLazyUpdates( ) { |
— | — | @@ -701,17 +728,6 @@ |
702 | 729 | $this->article = $ancestor->article(); |
703 | 730 | } |
704 | 731 | |
705 | | - // Populate reply count |
706 | | - if ( $this->replyCount == - 1 ) { |
707 | | - $dbr = wfGetDB( DB_SLAVE ); |
708 | | - |
709 | | - $count = $dbr->selectField( 'thread', 'count(*)', |
710 | | - array( 'thread_ancestor' => $this->id() ), __METHOD__ ); |
711 | | - |
712 | | - $this->replyCount = $count; |
713 | | - $set['thread_replies'] = $count; |
714 | | - } |
715 | | - |
716 | 732 | // Check for invalid/missing articleId |
717 | 733 | $articleTitle = null; |
718 | 734 | $dbTitle = Title::makeTitleSafe( $this->articleNamespace, $this->articleTitle ); |
Property changes on: branches/wmf-deployment/extensions/LiquidThreads |
___________________________________________________________________ |
Name: svn:mergeinfo |
719 | 735 | - /branches/REL1_15/phase3/extensions/LiquidThreads:51646 |
/trunk/extensions/LiquidThreads:56151-57571 |
/trunk/phase3/extensions/LiquidThreads:56213,56215-56216,56218,56325,56334-56336,56338,56340,56343,56345,56347,56350,57154-57447 |
720 | 736 | + /branches/REL1_15/phase3/extensions/LiquidThreads:51646 |
/trunk/extensions/LiquidThreads:56151-57571,57651 |
/trunk/phase3/extensions/LiquidThreads:56213,56215-56216,56218,56325,56334-56336,56338,56340,56343,56345,56347,56350,57154-57447 |