r97810 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r97809‎ | r97810 | r97811 >
Date:12:14, 22 September 2011
Author:reedy
Status:ok (Comments)
Tags:
Comment:
* (bug 31081) $wgEnotifUseJobQ causes many unnecessary jobs to be queued

Do some of the cheap checks before spawning attempting to send emails via any method
Modified paths:
  • /trunk/phase3/RELEASE-NOTES-1.19 (modified) (history)
  • /trunk/phase3/includes/UserMailer.php (modified) (history)
  • /trunk/phase3/includes/job/EnotifNotifyJob.php (modified) (history)

Diff [purge]

Index: trunk/phase3/RELEASE-NOTES-1.19
@@ -96,6 +96,7 @@
9797 really small, and somewhat inconsistent with each other.
9898 * Per page edit-notices now work in namespaces without subpages enabled.
9999 * (bug 30245) Use the correct way to construct a log page title
 100+* (bug 31081) $wgEnotifUseJobQ causes many unnecessary jobs to be queued
100101
101102 === API changes in 1.19 ===
102103 * (bug 19838) siprop=interwikimap can now use the interwiki cache.
Index: trunk/phase3/includes/UserMailer.php
@@ -364,7 +364,8 @@
365365 * @param $oldid (default: false)
366366 */
367367 public function notifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid = false ) {
368 - global $wgEnotifUseJobQ, $wgEnotifWatchlist, $wgShowUpdatedMarker;
 368+ global $wgEnotifUseJobQ, $wgEnotifWatchlist, $wgShowUpdatedMarker, $wgEnotifMinorEdits,
 369+ $wgUsersNotifiedOnAllChanges, $wgEnotifUserTalk;
369370
370371 if ( $title->getNamespace() < 0 ) {
371372 return;
@@ -403,6 +404,24 @@
404405 }
405406 }
406407
 408+ $sendEmail = true;
 409+ // If nobody is watching the page, and there are no users notified on all changes
 410+ // don't bother creating a job/trying to send emails
 411+ // $watchers deals with $wgEnotifWatchlist
 412+ if ( !count( $watchers ) && !count( $wgUsersNotifiedOnAllChanges ) ) {
 413+ $sendEmail = false;
 414+ // Only send notification for non minor edits, unless $wgEnotifMinorEdits
 415+ if ( !$minorEdit || ( $wgEnotifMinorEdits && !$editor->isAllowed( 'nominornewtalk' ) ) ) {
 416+ $isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK );
 417+ if ( $wgEnotifUserTalk && $isUserTalkPage && $this->canSendUserTalkEmail( $editor, $title, $minorEdit ) ) {
 418+ $sendEmail = true;
 419+ }
 420+ }
 421+ }
 422+
 423+ if ( !$sendEmail ) {
 424+ return;
 425+ }
407426 if ( $wgEnotifUseJobQ ) {
408427 $params = array(
409428 'editor' => $editor->getName(),
@@ -418,7 +437,6 @@
419438 } else {
420439 $this->actuallyNotifyOnPageChange( $editor, $title, $timestamp, $summary, $minorEdit, $oldid, $watchers );
421440 }
422 -
423441 }
424442
425443 /**
@@ -459,25 +477,11 @@
460478 $userTalkId = false;
461479
462480 if ( !$minorEdit || ( $wgEnotifMinorEdits && !$editor->isAllowed( 'nominornewtalk' ) ) ) {
463 - if ( $wgEnotifUserTalk && $isUserTalkPage ) {
 481+
 482+ if ( $wgEnotifUserTalk && $isUserTalkPage && $this->canSendUserTalkEmail( $editor, $title, $minorEdit ) ) {
464483 $targetUser = User::newFromName( $title->getText() );
465 - if ( !$targetUser || $targetUser->isAnon() ) {
466 - wfDebug( __METHOD__ . ": user talk page edited, but user does not exist\n" );
467 - } elseif ( $targetUser->getId() == $editor->getId() ) {
468 - wfDebug( __METHOD__ . ": user edited their own talk page, no notification sent\n" );
469 - } elseif ( $targetUser->getOption( 'enotifusertalkpages' ) &&
470 - ( !$minorEdit || $targetUser->getOption( 'enotifminoredits' ) ) )
471 - {
472 - if ( $targetUser->isEmailConfirmed() ) {
473 - wfDebug( __METHOD__ . ": sending talk page update notification\n" );
474 - $this->compose( $targetUser );
475 - $userTalkId = $targetUser->getId();
476 - } else {
477 - wfDebug( __METHOD__ . ": talk page owner doesn't have validated email\n" );
478 - }
479 - } else {
480 - wfDebug( __METHOD__ . ": talk page owner doesn't want notifications\n" );
481 - }
 484+ $this->compose( $targetUser );
 485+ $userTalkId = $targetUser->getId();
482486 }
483487
484488 if ( $wgEnotifWatchlist ) {
@@ -506,6 +510,39 @@
507511 }
508512
509513 /**
 514+ * @param $editor User
 515+ * @param $title Title bool
 516+ * @param $minorEdit
 517+ * @return bool
 518+ */
 519+ private function canSendUserTalkEmail( $editor, $title, $minorEdit ) {
 520+ global $wgEnotifUserTalk;
 521+ $isUserTalkPage = ( $title->getNamespace() == NS_USER_TALK );
 522+
 523+ if ( $wgEnotifUserTalk && $isUserTalkPage ) {
 524+ $targetUser = User::newFromName( $title->getText() );
 525+
 526+ if ( !$targetUser || $targetUser->isAnon() ) {
 527+ wfDebug( __METHOD__ . ": user talk page edited, but user does not exist\n" );
 528+ } elseif ( $targetUser->getId() == $editor->getId() ) {
 529+ wfDebug( __METHOD__ . ": user edited their own talk page, no notification sent\n" );
 530+ } elseif ( $targetUser->getOption( 'enotifusertalkpages' ) &&
 531+ ( !$minorEdit || $targetUser->getOption( 'enotifminoredits' ) ) )
 532+ {
 533+ if ( $targetUser->isEmailConfirmed() ) {
 534+ wfDebug( __METHOD__ . ": sending talk page update notification\n" );
 535+ return true;
 536+ } else {
 537+ wfDebug( __METHOD__ . ": talk page owner doesn't have validated email\n" );
 538+ }
 539+ } else {
 540+ wfDebug( __METHOD__ . ": talk page owner doesn't want notifications\n" );
 541+ }
 542+ }
 543+ return false;
 544+ }
 545+
 546+ /**
510547 * Generate the generic "this page has been changed" e-mail text.
511548 */
512549 private function composeCommonMailtext() {
Index: trunk/phase3/includes/job/EnotifNotifyJob.php
@@ -20,7 +20,7 @@
2121 function run() {
2222 $enotif = new EmailNotification();
2323 // Get the user from ID (rename safe). Anons are 0, so defer to name.
24 - if( isset($this->params['editorID']) && $this->params['editorID'] ) {
 24+ if( isset( $this->params['editorID'] ) && $this->params['editorID'] ) {
2525 $editor = User::newFromId( $this->params['editorID'] );
2626 // B/C, only the name might be given.
2727 } else {

Follow-up revisions

RevisionCommit summaryAuthorDate
r99646MFT r97810reedy19:11, 12 October 2011

Comments

#Comment by Reedy (talk | contribs)   12:16, 22 September 2011

Makes sense to push this into 1.18wmf1, might be useful to push into 1.18 anyway...

#Comment by Aaron Schulz (talk | contribs)   17:11, 22 September 2011

Why are you checking $editor->isAllowed( 'nominornewtalk' ) but not whether it it a talk page edit?

#Comment by Reedy (talk | contribs)   17:52, 22 September 2011

Seems I've eaten an option in the top version

-				} elseif ( $targetUser->getOption( 'enotifusertalkpages' ) &&


Also, that's how it was in the original code...

#Comment by Reedy (talk | contribs)   18:49, 22 September 2011

Ignore my first comment

Status & tagging log