r61770 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61769‎ | r61770 | r61771 >
Date:00:49, 1 February 2010
Author:werdna
Status:deferred
Tags:
Comment:
LiquidThreads: Query consolidation updates.
* Allow protection of non-top-level threads and non-existent pages in the thread namespace. Saves several hundred/thousand queries per LiquidThreads page view.
* Fix instance caching of negative results for LiquidThreads user overrides. Saves several hundred of the *same* query per LiquidThreads page view.
* Pre-cache article data for the talk page, saves a few hundred of the same query per LiquidThreads page view.
* Add short-circuits for non-existent pages in LiquidThreads dispatch code.
* Add short-circuit for Thread and Summary pages in LiquidThreads dispatch code.
Modified paths:
  • /trunk/extensions/LiquidThreads/classes/Dispatch.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/Hooks.php (modified) (history)
  • /trunk/extensions/LiquidThreads/classes/Thread.php (modified) (history)

Diff [purge]

Index: trunk/extensions/LiquidThreads/classes/Dispatch.php
@@ -2,7 +2,7 @@
33
44 class LqtDispatch {
55 /** static cache of per-page LiquidThreads activation setting */
6 - static $userLqtOverride;
 6+ static $userLqtOverride = array();
77 static $primaryView = null;
88
99 static function talkpageMain( &$output, &$article, &$title, &$user, &$request ) {
@@ -50,6 +50,8 @@
5151 $viewname = 'TalkpageView';
5252 }
5353
 54+ Thread::$titleCacheById[$article->getId()] = $title;
 55+
5456 $view = new $viewname( $output, $article, $title, $user, $request );
5557 self::$primaryView = $view;
5658 return $view->show();
@@ -94,12 +96,22 @@
9597 }
9698
9799 static function isLqtPage( $title ) {
 100+ // Ignore it if it's a thread or a summary, makes no sense to have LiquidThreads there.
 101+ if ( $title->getNamespace() == NS_LQT_THREAD ||
 102+ $title->getNamespace() == NS_LQT_SUMMARY ) {
 103+ return false;
 104+ }
 105+
98106 global $wgLqtPages, $wgLqtTalkPages;
99107 $isTalkPage = ( $title->isTalkPage() && $wgLqtTalkPages ) ||
100108 in_array( $title->getPrefixedText(), $wgLqtPages );
101 -
102 - $override = self::getUserLqtOverride( $title->getArticleId() );
103109
 110+ if ( $title->exists() ) {
 111+ $override = self::getUserLqtOverride( $title->getArticleId() );
 112+ } else {
 113+ $override = null;
 114+ }
 115+
104116 global $wgLiquidThreadsAllowUserControl;
105117 if ( !is_null($override) && $wgLiquidThreadsAllowUserControl ) {
106118 $isTalkPage = $override;
@@ -115,8 +127,8 @@
116128 $article = $article->getId();
117129 }
118130
119 - // Instance cache
120 - if ( isset( self::$userLqtOverride[$article] ) ) {
 131+ // Check instance cache.
 132+ if ( array_key_exists( $article, self::$userLqtOverride ) ) {
121133 $cacheVal = self::$userLqtOverride[$article];
122134
123135 return $cacheVal;
@@ -143,6 +155,7 @@
144156 $row = $dbr->selectRow( 'page_props', 'pp_value',
145157 array( 'pp_propname' => 'use-liquid-threads',
146158 'pp_page' => $article ), __METHOD__ );
 159+
147160
148161 if ( $row ) {
149162 $dbVal = $row->pp_value;
Index: trunk/extensions/LiquidThreads/classes/Hooks.php
@@ -418,11 +418,6 @@
419419 static function getProtectionTypes( $title, &$types ) {
420420 $isLqtPage = LqtDispatch::isLqtPage( $title );
421421 $isThread = $title->getNamespace() == NS_LQT_THREAD;
422 -
423 - // Bulk load is a no-no, causes infinite recursion.
424 - $thread = Threads::withRoot( new Article( $title ), false );
425 -
426 - $isThread = $isThread && $thread && $thread->isTopmostThread();
427422
428423 if ( !$isLqtPage && !$isThread ) {
429424 return true;
Index: trunk/extensions/LiquidThreads/classes/Thread.php
@@ -981,11 +981,23 @@
982982 if ( $this->article ) return $this->article;
983983
984984 if ( !is_null( $this->articleId ) ) {
985 - $title = Title::newFromID( $this->articleId );
 985+ if ( isset( self::$articleCacheById[$this->articleId] ) ) {
 986+ return self::$articleCacheById[$this->articleId];
 987+ }
 988+
 989+ if ( isset( self::$titleCacheById[$this->articleId] ) ) {
 990+ $title = self::$titleCacheById[$this->articleId];
 991+ } else {
 992+ $title = Title::newFromID( $this->articleId );
 993+ }
 994+
986995 if ( $title ) {
987996 $article = new Article_LQT_Compat( $title );
988997 }
 998+
 999+ self::$articleCacheById[$this->articleId] = $article;
9891000 }
 1001+
9901002 if ( isset( $article ) && $article->exists() ) {
9911003 $this->article = $article;
9921004 return $article;

Status & tagging log