Index: trunk/extensions/LiquidThreads/classes/Thread.php |
— | — | @@ -53,6 +53,7 @@ |
54 | 54 | |
55 | 55 | static $titleCacheById = array(); |
56 | 56 | static $replyCacheById = array(); |
| 57 | + static $articleCacheById = array(); |
57 | 58 | |
58 | 59 | function isHistorical() { |
59 | 60 | return false; |
— | — | @@ -272,12 +273,12 @@ |
273 | 274 | $redirectText = $mwRedir->getSynonym( 0 ) . ' [[' . $this->title()->getPrefixedText() . "]]\n"; |
274 | 275 | |
275 | 276 | // 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 ); |
278 | 279 | $redirectArticle->doEdit( $redirectText, $reason, EDIT_NEW ); |
279 | 280 | |
280 | 281 | // 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, |
282 | 283 | Threads::TYPE_MOVED, $this->subject() ); |
283 | 284 | } |
284 | 285 | |
— | — | @@ -317,7 +318,7 @@ |
318 | 319 | |
319 | 320 | if ( isset($line->page_namespace) && isset($line->page_title) ) { |
320 | 321 | $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 ); |
322 | 323 | $this->root->loadPageData( $line ); |
323 | 324 | } else { |
324 | 325 | if ( isset( self::$titleCacheById[$this->rootId] ) ) { |
— | — | @@ -327,7 +328,7 @@ |
328 | 329 | } |
329 | 330 | |
330 | 331 | if ($root_title) { |
331 | | - $this->root = new Article( $root_title ); |
| 332 | + $this->root = new Article_LQT_Compat( $root_title ); |
332 | 333 | $this->rootRevision = $this->root->mLatest; |
333 | 334 | } |
334 | 335 | } |
— | — | @@ -340,6 +341,7 @@ |
341 | 342 | // Preload subthreads |
342 | 343 | $thread_ids = array(); |
343 | 344 | $pageIds = array(); |
| 345 | + $linkBatch = new LinkBatch(); |
344 | 346 | |
345 | 347 | if (!is_array(self::$replyCacheById)) { |
346 | 348 | self::$replyCacheById = array(); |
— | — | @@ -353,6 +355,10 @@ |
354 | 356 | $pageIds[] = $row->thread_root; |
355 | 357 | if ($row->thread_summary_page) |
356 | 358 | $pageIds[] = $row->thread_summary_page; |
| 359 | + |
| 360 | + if ( !isset( self::$replyCacheById[$row->thread_id] ) ) { |
| 361 | + self::$replyCacheById[$row->thread_id] = array(); |
| 362 | + } |
357 | 363 | } |
358 | 364 | |
359 | 365 | if ( count($thread_ids) ) { |
— | — | @@ -362,31 +368,47 @@ |
363 | 369 | |
364 | 370 | while( $row = $dbr->fetchObject($res) ) { |
365 | 371 | // Grab page data while we're here. |
| 372 | + $rows[] = $row; |
366 | 373 | if ($row->thread_root) |
367 | 374 | $pageIds[] = $row->thread_root; |
368 | 375 | if ($row->thread_summary_page) |
369 | 376 | $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 | | - } |
375 | 377 | |
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(); |
378 | 380 | } |
379 | 381 | } |
380 | 382 | } |
381 | 383 | |
382 | 384 | // Preload page data in one swoop. |
| 385 | + $articlesById = array(); |
383 | 386 | 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 | + |
384 | 396 | $res = $dbr->select( 'page', '*', array( 'page_id' => $pageIds ), __METHOD__ ); |
| 397 | + |
385 | 398 | while( $row = $dbr->fetchObject( $res ) ) { |
386 | 399 | $t = Title::newFromRow( $row ); |
387 | 400 | |
| 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 | + |
388 | 409 | self::$titleCacheById[$t->getArticleId()] = $t; |
| 410 | + $articlesById[$article->getId()] = $article; |
389 | 411 | |
390 | | - if ( count(self::$titleCacheById) > 1000 ) { |
| 412 | + if ( count(self::$titleCacheById) > 10000 ) { |
391 | 413 | self::$titleCacheById = array(); |
392 | 414 | } |
393 | 415 | } |
— | — | @@ -395,10 +417,25 @@ |
396 | 418 | $threads = array(); |
397 | 419 | |
398 | 420 | 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]; |
400 | 423 | 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 | + } |
401 | 436 | } |
402 | 437 | |
| 438 | + $linkBatch->execute(); |
| 439 | + |
403 | 440 | return $threads; |
404 | 441 | } |
405 | 442 | |
— | — | @@ -488,7 +525,7 @@ |
489 | 526 | LqtDispatch::isLqtPage( $articleTitle->getTalkPage() ) && |
490 | 527 | $articleTitle->getNamespace() != NS_LQT_THREAD ) { |
491 | 528 | $newTitle = $articleTitle->getTalkPage(); |
492 | | - $newArticle = new Article( $newTitle ); |
| 529 | + $newArticle = new Article_LQT_Compat( $newTitle ); |
493 | 530 | |
494 | 531 | $set['thread_article_namespace'] = $newTitle->getNamespace(); |
495 | 532 | $set['thread_article_title'] = $newTitle->getDbKey(); |
— | — | @@ -672,7 +709,7 @@ |
673 | 710 | if ( !is_null( $this->articleId ) ) { |
674 | 711 | $title = Title::newFromID( $this->articleId ); |
675 | 712 | if ( $title ) { |
676 | | - $article = new Article( $title ); |
| 713 | + $article = new Article_LQT_Compat( $title ); |
677 | 714 | } |
678 | 715 | } |
679 | 716 | if ( isset( $article ) && $article->exists() ) { |
— | — | @@ -680,7 +717,7 @@ |
681 | 718 | return $article; |
682 | 719 | } else { |
683 | 720 | $title = Title::makeTitle( $this->articleNamespace, $this->articleTitle ); |
684 | | - return new Article( $title ); |
| 721 | + return new Article_LQT_Compat( $title ); |
685 | 722 | } |
686 | 723 | } |
687 | 724 | |
— | — | @@ -696,10 +733,20 @@ |
697 | 734 | function root() { |
698 | 735 | if ( !$this->rootId ) return null; |
699 | 736 | 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 | + |
701 | 748 | if (!$title) return null; |
702 | 749 | |
703 | | - $this->root = new Article( $title, $this->rootRevision() ); |
| 750 | + $this->root = new Article_LQT_Compat( $title, $this->rootRevision() ); |
704 | 751 | } |
705 | 752 | return $this->root; |
706 | 753 | } |
— | — | @@ -733,7 +780,7 @@ |
734 | 781 | return null; |
735 | 782 | } |
736 | 783 | |
737 | | - $this->summary = new Article( $title ); |
| 784 | + $this->summary = new Article_LQT_Compat( $title ); |
738 | 785 | |
739 | 786 | } |
740 | 787 | |
— | — | @@ -857,7 +904,7 @@ |
858 | 905 | $rev = Revision::newFromId( $this->root()->getLatest() ); |
859 | 906 | $rtitle = Title::newFromRedirect( $rev->getRawText() ); |
860 | 907 | if ( !$rtitle ) return null; |
861 | | - $rthread = Threads::withRoot( new Article( $rtitle ) ); |
| 908 | + $rthread = Threads::withRoot( new Article_LQT_Compat( $rtitle ) ); |
862 | 909 | return $rthread; |
863 | 910 | } |
864 | 911 | |