r47927 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47926‎ | r47927 | r47928 >
Date:12:15, 2 March 2009
Author:catrope
Status:resolved (Comments)
Tags:
Comment:
(bug 10172) Move setting the "changed since last visit" flags out of the job queue:
* Move up the UPDATE query on wl_notificationtimestamp up to before scheduling the EnotifyNotifyJob
* Move up the SELECT query fetching the users to be notified to before the UPDATE, and use its result for a more efficient UPDATE
* Pass actuallyNotifyOnPageChange() and the EnotifyNotifyJob an array of user IDs
* Add UserArray::newFromIDs()
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/EnotifNotifyJob.php (modified) (history)
  • /trunk/phase3/includes/UserArray.php (modified) (history)
  • /trunk/phase3/includes/UserMailer.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/UserArray.php
@@ -12,6 +12,17 @@
1313 return $userArray;
1414 }
1515
 16+ static function newFromIDs( $ids ) {
 17+ $ids = array_map( 'intval', (array)$ids ); // paranoia
 18+ if ( !$ids )
 19+ // Database::select() doesn't like empty arrays
 20+ return new ArrayIterator(array());
 21+ $dbr = wfGetDB( DB_SLAVE );
 22+ $res = $dbr->select( 'user', '*', array( 'user_id' => $ids ),
 23+ __METHOD__ );
 24+ return self::newFromResult( $res );
 25+ }
 26+
1627 protected static function newFromResult_internal( $res ) {
1728 $userArray = new UserArrayFromResult( $res );
1829 return $userArray;
Index: trunk/phase3/includes/EnotifNotifyJob.php
@@ -26,7 +26,8 @@
2727 $this->params['timestamp'],
2828 $this->params['summary'],
2929 $this->params['minorEdit'],
30 - $this->params['oldid']
 30+ $this->params['oldid'],
 31+ $this->params['watchers']
3132 );
3233 return true;
3334 }
Index: trunk/phase3/includes/UserMailer.php
@@ -281,11 +281,42 @@
282282 * @param $oldid (default: false)
283283 */
284284 function notifyOnPageChange($editor, $title, $timestamp, $summary, $minorEdit, $oldid = false) {
285 - global $wgEnotifUseJobQ;
 285+ global $wgEnotifUseJobQ, $wgEnotifWatchlist, $wgShowUpdatedMarker;
286286
287 - if( $title->getNamespace() < 0 )
 287+ if ($title->getNamespace() < 0)
288288 return;
289289
 290+ // Build a list of users to notfiy
 291+ $watchers = array();
 292+ if ($wgEnotifWatchlist || $wgShowUpdatedMarker) {
 293+ $dbw = wfGetDB( DB_MASTER );
 294+ $res = $dbw->select( array( 'watchlist' ),
 295+ array( 'wl_user' ),
 296+ array(
 297+ 'wl_title' => $title->getDBkey(),
 298+ 'wl_namespace' => $title->getNamespace(),
 299+ 'wl_user != ' . intval( $editor->getID() ),
 300+ 'wl_notificationtimestamp IS NULL',
 301+ ), __METHOD__
 302+ );
 303+ while ($row = $dbw->fetchObject( $res ) ) {
 304+ $watchers[] = intval( $row->wl_user );
 305+ }
 306+ if ($watchers) {
 307+ // Update wl_notificationtimestamp for all watching users except
 308+ // the editor
 309+ $dbw->begin();
 310+ $dbw->update( 'watchlist',
 311+ array( /* SET */
 312+ 'wl_notificationtimestamp' => $dbw->timestamp( $timestamp )
 313+ ), array( /* WHERE */
 314+ 'wl_user' => $watchers
 315+ ), __METHOD__
 316+ );
 317+ $dbw->commit();
 318+ }
 319+ }
 320+
290321 if ($wgEnotifUseJobQ) {
291322 $params = array(
292323 "editor" => $editor->getName(),
@@ -293,11 +324,12 @@
294325 "timestamp" => $timestamp,
295326 "summary" => $summary,
296327 "minorEdit" => $minorEdit,
297 - "oldid" => $oldid);
 328+ "oldid" => $oldid,
 329+ "watchers" => $watchers);
298330 $job = new EnotifNotifyJob( $title, $params );
299331 $job->insert();
300332 } else {
301 - $this->actuallyNotifyOnPageChange($editor, $title, $timestamp, $summary, $minorEdit, $oldid);
 333+ $this->actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers );
302334 }
303335
304336 }
@@ -310,15 +342,16 @@
311343 *
312344 * @param $editor User object
313345 * @param $title Title object
314 - * @param $timestamp
315 - * @param $summary
316 - * @param $minorEdit
317 - * @param $oldid (default: false)
 346+ * @param $timestamp string Edit timestamp
 347+ * @param $summary string Edit summary
 348+ * @param $minorEdit bool
 349+ * @param $oldid int Revision ID
 350+ * @param $watchers array of user IDs
318351 */
319 - function actuallyNotifyOnPageChange($editor, $title, $timestamp, $summary, $minorEdit, $oldid=false) {
 352+ function actuallyNotifyOnPageChange($editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers) {
320353 # we use $wgPasswordSender as sender's address
321354 global $wgEnotifWatchlist;
322 - global $wgEnotifMinorEdits, $wgEnotifUserTalk, $wgShowUpdatedMarker;
 355+ global $wgEnotifMinorEdits, $wgEnotifUserTalk;
323356 global $wgEnotifImpersonal;
324357
325358 wfProfileIn( __METHOD__ );
@@ -363,30 +396,12 @@
364397
365398 if ( $wgEnotifWatchlist ) {
366399 // Send updates to watchers other than the current editor
367 - $userCondition = 'wl_user != ' . intval( $editor->getID() );
368 - if ( $userTalkId !== false ) {
369 - // Already sent an email to this person
370 - $userCondition .= ' AND wl_user != ' . intval( $userTalkId );
371 - }
372 - $dbr = wfGetDB( DB_SLAVE );
373 -
374 - list( $user ) = $dbr->tableNamesN( 'user' );
375 - $res = $dbr->select( array( 'watchlist', 'user' ),
376 - array( "$user.*" ),
377 - array(
378 - 'wl_user=user_id',
379 - 'wl_title' => $title->getDBkey(),
380 - 'wl_namespace' => $title->getNamespace(),
381 - $userCondition,
382 - 'wl_notificationtimestamp IS NULL',
383 - ), __METHOD__
384 - );
385 - $userArray = UserArray::newFromResult( $res );
386 -
 400+ $userArray = UserArray::newFromIDs( $watchers );
387401 foreach ( $userArray as $watchingUser ) {
388402 if ( $watchingUser->getOption( 'enotifwatchlistpages' ) &&
389403 ( !$minorEdit || $watchingUser->getOption('enotifminoredits') ) &&
390 - $watchingUser->isEmailConfirmed() )
 404+ $watchingUser->isEmailConfirmed() &&
 405+ $watchingUser->getID() != $userTalkId )
391406 {
392407 $this->compose( $watchingUser );
393408 }
@@ -400,31 +415,9 @@
401416 $this->compose( $user );
402417 }
403418
404 - $latestTimestamp = Revision::getTimestampFromId( $title, $title->getLatestRevID(GAID_FOR_UPDATE) );
405 - // Do not update watchlists if something else already did.
406 - if ( $timestamp >= $latestTimestamp && ($wgShowUpdatedMarker || $wgEnotifWatchlist) ) {
407 - # Mark the changed watch-listed page with a timestamp, so that the page is
408 - # listed with an "updated since your last visit" icon in the watch list. Do
409 - # not do this to users for their own edits.
410 - $dbw = wfGetDB( DB_MASTER );
411 - $dbw->begin();
412 - $dbw->update( 'watchlist',
413 - array( /* SET */
414 - 'wl_notificationtimestamp' => $dbw->timestamp($timestamp)
415 - ), array( /* WHERE */
416 - 'wl_title' => $title->getDBkey(),
417 - 'wl_namespace' => $title->getNamespace(),
418 - 'wl_notificationtimestamp IS NULL', // store oldest unseen change time
419 - 'wl_user != ' . intval( $editor->getID() )
420 - ), __METHOD__
421 - );
422 - $dbw->commit();
423 - }
424 -
425419 $this->sendMails();
426 -
427420 wfProfileOut( __METHOD__ );
428 - } # function NotifyOnChange
 421+ }
429422
430423 /**
431424 * @private
Index: trunk/phase3/RELEASE-NOTES
@@ -225,10 +225,13 @@
226226 * (bug 17546) Correct Tongan language native name is "lea faka-Tonga"
227227 * (bug 17621) Special:WantedFiles has no link to Special:Whatlinkshere
228228 * (bug 17460) Client ecoding is now correctly set for PostgreSQL
229 -* (bug 17648) Prevent floats from intruding into edit area in previews if no toolbar present
 229+* (bug 17648) Prevent floats from intruding into edit area in previews if no
 230+ toolbar present
230231 * (bug 16899) DISPLAYTITLE should allow Arabic and Persian harakats
231232 * (bug 17692) Added (list of members) link to 'user' in Special:Listgrouprights
232233 * (bug 17707) Show file destination as plain text if &wpForReUpload=1
 234+* (bug 10172) Moved setting of "changed since last visit" flags out of the job
 235+ queue
233236
234237 == API changes in 1.15 ==
235238 * (bug 16858) Revamped list=deletedrevs to make listing deleted contributions

Follow-up revisions

RevisionCommit summaryAuthorDate
r49682fix regression from r47927vyznev23:14, 20 April 2009
r50093* Backported r49682: fixes total breakage of the "changed since last visit" f...tstarling06:09, 1 May 2009

Comments

#Comment by Catrope (talk | contribs)   12:22, 2 March 2009

This is arguably a regression of r22110 (!), which put the UPDATE query in the job queue in the first place

#Comment by Brion VIBBER (talk | contribs)   06:54, 25 March 2009

Per discussion with Tim, it should do well enough for now. We'll want to do biger refactoring on this whole queue model at some point though...

#Comment by Mormegil (talk | contribs)   19:12, 20 April 2009

D’oh! Maybe I am blind, but in

               $dbw->update( 'watchlist',
                   array( /* SET */
                       'wl_notificationtimestamp' => $dbw->timestamp( $timestamp )
                   ), array( /* WHERE */
                       'wl_user' => $watchers
                   ), __METHOD__
               );

the WHERE clause seems really a bit too short to me… Shouldn’t there be also wl_namespace and wl_title?!?

#Comment by Ilmari Karonen (talk | contribs)   22:11, 20 April 2009

Oh dear, yes, that does seem broken. :-(

#Comment by Ilmari Karonen (talk | contribs)   23:17, 20 April 2009

Should be fixed in r49682, thanks for noticing it.

Status & tagging log