r42232 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r42231‎ | r42232 | r42233 >
Date:23:08, 19 October 2008
Author:brion
Status:old
Tags:
Comment:
Backing out r42128 for now "added 'UnwatchArticle', 'WatchArticle' and 'WatchArticleComplete' in response to code review of rev 42109"
Article::newFromId() does an individual id->title lookup in the database, making this potentially very expensive -- we could run thousands of queries in a row.
Modified paths:
  • /trunk/phase3/includes/WatchlistEditor.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/WatchlistEditor.php
@@ -269,18 +269,10 @@
270270 private function watchTitles( $titles, $user ) {
271271 $dbw = wfGetDB( DB_MASTER );
272272 $rows = array();
273 - $articles = array();
274273 foreach( $titles as $title ) {
275274 if( !$title instanceof Title )
276275 $title = Title::newFromText( $title );
277276 if( $title instanceof Title ) {
278 - $article = new Article( $title );
279 - if ( !wfRunHooks('WatchArticle',array( &$user, &$article ) ) ){
280 - continue;
281 - }
282 - // queue the ids rather than the objects, since the hook could potentially
283 - // load the entire object and make memory trouble
284 - $articleIds[] = $article->getID();
285277 $rows[] = array(
286278 'wl_user' => $user->getId(),
287279 'wl_namespace' => ( $title->getNamespace() & ~1 ),
@@ -296,10 +288,6 @@
297289 }
298290 }
299291 $dbw->insert( 'watchlist', $rows, __METHOD__, 'IGNORE' );
300 - foreach( $articleIds as $articleId ){
301 - $article = Article::newFromID($articleId);
302 - wfRunHooks('WatchArticleComplete',array(&$user,&$article));
303 - }
304292 }
305293
306294 /**
@@ -317,10 +305,6 @@
318306 if( !$title instanceof Title )
319307 $title = Title::newFromText( $title );
320308 if( $title instanceof Title ) {
321 - $article = new Article($title);
322 - if(!wfRunHooks('UnwatchArticle',array(&$user,&$article))){
323 - continue;
324 - }
325309 $dbw->delete(
326310 'watchlist',
327311 array(
@@ -339,6 +323,7 @@
340324 ),
341325 __METHOD__
342326 );
 327+ $article = new Article($title);
343328 wfRunHooks('UnwatchArticleComplete',array(&$user,&$article));
344329 }
345330 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r42128added 'UnwatchArticle', 'WatchArticle' and 'WatchArticleComplete' in response...jasonr23:53, 15 October 2008

Status & tagging log