r28009 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r28008‎ | r28009 | r28010 >
Date:09:48, 1 December 2007
Author:nikerabbit
Status:old
Tags:
Comment:
* Don't bother making title objects
* Reduced count watchers query count by caching and ignoring special namespaces (could still do only a one query)
Modified paths:
  • /trunk/phase3/includes/SpecialRecentchanges.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialRecentchanges.php
@@ -172,13 +172,9 @@
173173 while( $row = $dbr->fetchObject( $res ) ){
174174 $rows[] = $row;
175175 if ( !$feedFormat ) {
176 - // User page link
177 - $title = Title::makeTitleSafe( NS_USER, $row->rc_user_text );
178 - $batch->addObj( $title );
179 -
180 - // User talk
181 - $title = Title::makeTitleSafe( NS_USER_TALK, $row->rc_user_text );
182 - $batch->addObj( $title );
 176+ // User page and talk links
 177+ $batch->add( NS_USER, $row->rc_user_text );
 178+ $batch->add( NS_USER_TALK, $row->rc_user_text );
183179 }
184180
185181 }
@@ -231,6 +227,10 @@
232228
233229 $s = $list->beginRecentChangesList();
234230 $counter = 1;
 231+
 232+ $showWatcherCount = $wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' );
 233+ $watcherCache = array();
 234+
235235 foreach( $rows as $obj ){
236236 if( $limit == 0) {
237237 break;
@@ -249,13 +249,20 @@
250250 $rc->notificationtimestamp = false;
251251 }
252252
253 - if ($wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
254 - $sql3 = "SELECT COUNT(*) AS n FROM $watchlist WHERE wl_title='" . $dbr->strencode($obj->rc_title) ."' AND wl_namespace=$obj->rc_namespace" ;
255 - $res3 = $dbr->query( $sql3, 'wfSpecialRecentChanges');
256 - $x = $dbr->fetchObject( $res3 );
257 - $rc->numberofWatchingusers = $x->n;
258 - } else {
259 - $rc->numberofWatchingusers = 0;
 253+ $rc->numberofWatchingusers = 0; // Default
 254+ if ($showWatcherCount && $obj->rc_namespace >= 0) {
 255+ if (!isset($watcherCache[$obj->rc_namespace][$obj->rc_title])) {
 256+ $sql3 =
 257+ 'SELECT COUNT(*) AS n ' .
 258+ "FROM $watchlist " .
 259+ "WHERE wl_title='{$dbr->strencode($obj->rc_title)}' " .
 260+ "AND wl_namespace=$obj->rc_namespace" ;
 261+ $res3 = $dbr->query( $sql3, __METHOD__ . '-watchers');
 262+ $x = $dbr->fetchObject( $res3 );
 263+ $watcherCache[$obj->rc_namespace][$obj->rc_title] = $x->n;
 264+ $dbr->freeResult( $res3 );
 265+ }
 266+ $rc->numberofWatchingusers = $watcherCache[$obj->rc_namespace][$obj->rc_title];
260267 }
261268 $s .= $list->recentChangesLine( $rc, !empty( $obj->wl_user ) );
262269 --$limit;

Status & tagging log