From 2771b94af74b7405102f61466bbd76ed3253ad46 Mon Sep 17 00:00:00 2001 From: Catrope Date: Fri, 17 Jun 2016 13:43:22 +0000 Subject: [PATCH] Revert "Implement backfillUnreadWikis.php in terms of resetNotificationCount()" Better idea: invalidate caches in this script, and write a separate script to recompute existing euw rows. This reverts commit c83af257d2e65739bd96f0b9e0ed7fcf708db260. Change-Id: I57bccfb726eada646cb318206d9091a20d59dcf5 --- includes/NotifUser.php | 12 +++--------- maintenance/backfillUnreadWikis.php | 13 +++++++++++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/includes/NotifUser.php b/includes/NotifUser.php index a07ae4021..1755c9019 100644 --- a/includes/NotifUser.php +++ b/includes/NotifUser.php @@ -454,9 +454,8 @@ class MWEchoNotifUser { /** * Recalculates the number of notifications that a user has. * @param $dbSource int use master or slave database to pull count - * @param $deferUpdate bool Whether to defer the update to the echo_unread_wikis table */ - public function resetNotificationCount( $dbSource = DB_SLAVE, $deferUpdate = true ) { + public function resetNotificationCount( $dbSource = DB_SLAVE ) { global $wgEchoCrossWikiNotifications; // Reset alert and message counts, and store them for later $alertCount = $this->getNotificationCount( false, $dbSource, EchoAttributeManager::ALERT, false ); @@ -506,17 +505,12 @@ class MWEchoNotifUser { // Schedule an update to the echo_unread_wikis table $user = $this->mUser; - $updateCallback = function () use ( $user, $alertCount, $alertUnread, $msgCount, $msgUnread ) { + DeferredUpdates::addCallableUpdate( function () use ( $user, $alertCount, $alertUnread, $msgCount, $msgUnread ) { $uw = EchoUnreadWikis::newFromUser( $user ); if ( $uw ) { $uw->updateCount( wfWikiID(), $alertCount, $alertUnread, $msgCount, $msgUnread ); } - }; - if ( $deferUpdate ) { - DeferredUpdates::addCallableUpdate( $updateCallback ); - } else { - $updateCallback(); - } + } ); } $this->invalidateCache(); diff --git a/maintenance/backfillUnreadWikis.php b/maintenance/backfillUnreadWikis.php index 4e85a26ac..b95fb5d30 100644 --- a/maintenance/backfillUnreadWikis.php +++ b/maintenance/backfillUnreadWikis.php @@ -10,7 +10,7 @@ class BackfillUnreadWikis extends Maintenance { public function __construct() { parent::__construct(); - $this->mDescription = "Backfill echo_unread_wikis table and recache notification counts for all users"; + $this->mDescription = "Backfill echo_unread_wikis table"; $this->setBatchSize( 300 ); } @@ -28,7 +28,16 @@ class BackfillUnreadWikis extends Maintenance { $user = User::newFromRow( $row ); $notifUser = MWEchoNotifUser::newFromUser( $user ); - $notifUser->resetNotificationCount( DB_SLAVE, false ); + $uw = EchoUnreadWikis::newFromUser( $user ); + if ( $uw ) { + $alertCount = $notifUser->getNotificationCount( false, DB_SLAVE, EchoAttributeManager::ALERT, false ); + $alertUnread = $notifUser->getLastUnreadNotificationTime( false, DB_SLAVE, EchoAttributeManager::ALERT, false ); + + $msgCount = $notifUser->getNotificationCount( false, DB_SLAVE, EchoAttributeManager::MESSAGE, false ); + $msgUnread = $notifUser->getLastUnreadNotificationTime( false, DB_SLAVE, EchoAttributeManager::MESSAGE, false ); + + $uw->updateCount( wfWikiID(), $alertCount, $alertUnread, $msgCount, $msgUnread ); + } } $processed += count( $batch );