Index: branches/liquidthreads/extensions/LqtModel.php |
— | — | @@ -465,6 +465,10 @@ |
466 | 466 | $this->changeComment = $line->thread_change_comment; |
467 | 467 | $this->changeUser = $line->thread_change_user; |
468 | 468 | $this->changeUserText = $line->thread_change_user_text; |
| 469 | + |
| 470 | + } |
| 471 | + |
| 472 | + function initWithReplies( $children ) { |
469 | 473 | |
470 | 474 | $this->replies = $children; |
471 | 475 | |
— | — | @@ -476,6 +480,8 @@ |
477 | 481 | |
478 | 482 | (we could do Revision::getPrevious() we just need to know whether or not |
479 | 483 | there was a new revision saved at save time. make it run then make it right.) |
| 484 | + |
| 485 | + TODO this is expensive and should be ripped out. |
480 | 486 | */ |
481 | 487 | $rev = Revision::newFromTitle( $this->root()->getTitle() ); |
482 | 488 | $this->rootRevision = $rev->getId(); |
— | — | @@ -855,21 +861,46 @@ |
856 | 862 | SQL; |
857 | 863 | $res = $dbr->query($sql); |
858 | 864 | |
859 | | - $lines = array(); |
860 | 865 | $threads = array(); |
| 866 | + $top_level_threads = array(); |
861 | 867 | |
862 | 868 | while ( $line = $dbr->fetchObject($res) ) { |
863 | | - $lines[] = $line; |
| 869 | + $new_thread = new Thread($line, null); |
| 870 | + $threads[] = $new_thread; |
| 871 | + if( $line->is_root ) |
| 872 | + // thread is one of those that was directly queried for. |
| 873 | + $top_level_threads[] = $new_thread; |
| 874 | + if( strstr( $line->thread_path, '.' ) !== false ) { |
| 875 | + // thread has a parent. extract second-to-last path element. |
| 876 | + preg_match( '/([^.]+)\.[^.]+$/', $line->thread_path, $path_matches ); |
| 877 | + $parent_id = $path_matches[1]; |
| 878 | + if( !array_key_exists( $parent_id, self::$thread_children ) ) |
| 879 | + self::$thread_children[$parent_id] = array(); |
| 880 | + self::$thread_children[$parent_id][] = $new_thread; |
| 881 | + } |
864 | 882 | } |
865 | 883 | |
866 | | - foreach( $lines as $key => $l ) { |
867 | | - if( $l->is_root ) { |
868 | | -// unset($lines[$key]); |
869 | | - $threads[] = Threads::buildThread( $lines, $l ); |
| 884 | + foreach( $threads as $thread ) { |
| 885 | + if( array_key_exists( $thread->id(), self::$thread_children ) ) { |
| 886 | + $thread->initWithReplies( self::$thread_children[$thread->id()] ); |
| 887 | + } else { |
| 888 | + $thread->initWithReplies( array() ); |
870 | 889 | } |
871 | 890 | } |
872 | | - return $threads; |
| 891 | + return $top_level_threads; |
873 | 892 | } |
| 893 | + |
| 894 | + /* |
| 895 | + private function splitIncrementFromSubject($subject_string) { |
| 896 | + preg_match('/^(.*) \((\d+)\)$/', $subject_string, $matches); |
| 897 | + if( count($matches) != 3 ) |
| 898 | + throw new MWException( __METHOD__ . ": thread subject has no increment: " . $subject_string ); |
| 899 | + else |
| 900 | + return $matches; |
| 901 | + } |
| 902 | + */ |
| 903 | + |
| 904 | + static $thread_children = array(); |
874 | 905 | |
875 | 906 | private static function buildThread( $lines, $l ) { |
876 | 907 | $children = array(); |