Defer user_newtalk updates in clearNotification() to post-send
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 16 Jul 2015 23:06:13 +0000 (16:06 -0700)
committerOri.livneh <ori@wikimedia.org>
Fri, 17 Jul 2015 21:56:36 +0000 (21:56 +0000)
* Also only issue DELETE if notifications exist. Previously,
  this would issue a DELETE for all self talk page views.

Bug: T92007
Change-Id: Ifef11c9e5175d68d9615e59e2ed7de2f2c57bde1

includes/User.php

index bd0d30b..d627a6d 100644 (file)
@@ -3385,19 +3385,24 @@ class User implements IDBAccessObject {
                                return;
                        }
 
-                       $nextid = $oldid ? $title->getNextRevisionID( $oldid ) : null;
+                       $that = $this;
+                       // Try to update the DB post-send and only if needed...
+                       DeferredUpdates::addCallableUpdate( function() use ( $that, $title, $oldid ) {
+                               if ( !$that->getNewtalk() ) {
+                                       return; // no notifications to clear
+                               }
 
-                       if ( !$oldid || !$nextid ) {
-                               // If we're looking at the latest revision, we should definitely clear it
-                               $this->setNewtalk( false );
-                       } else {
-                               // Otherwise we should update its revision, if it's present
-                               if ( $this->getNewtalk() ) {
-                                       // Naturally the other one won't clear by itself
-                                       $this->setNewtalk( false );
-                                       $this->setNewtalk( true, Revision::newFromId( $nextid ) );
+                               // Delete the last notifications (they stack up)
+                               $that->setNewtalk( false );
+
+                               // If there is a new, unseen, revision, use its timestamp
+                               $nextid = $oldid
+                                       ? $title->getNextRevisionID( $oldid, Title::GAID_FOR_UPDATE )
+                                       : null;
+                               if ( $nextid ) {
+                                       $that->setNewtalk( true, Revision::newFromId( $nextid ) );
                                }
-                       }
+                       } );
                }
 
                if ( !$wgUseEnotif && !$wgShowUpdatedMarker ) {