From 64bf3a12b514bb0f88d90e268f388495e2554278 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 16 Jul 2015 16:06:13 -0700 Subject: [PATCH] Defer user_newtalk updates in clearNotification() to post-send * 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 | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/includes/User.php b/includes/User.php index bd0d30b517..d627a6db3c 100644 --- a/includes/User.php +++ b/includes/User.php @@ -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 ) { -- 2.20.1