Merge "Implement backfillUnreadWikis.php in terms of resetNotificationCount()"

This commit is contained in:
jenkins-bot 2016-06-11 15:54:55 +00:00 committed by Gerrit Code Review
commit d3e1846666
2 changed files with 11 additions and 14 deletions

View file

@ -454,8 +454,9 @@ 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 ) {
public function resetNotificationCount( $dbSource = DB_SLAVE, $deferUpdate = true ) {
global $wgEchoCrossWikiNotifications;
// Reset alert and message counts, and store them for later
$alertCount = $this->getNotificationCount( false, $dbSource, EchoAttributeManager::ALERT, false );
@ -505,12 +506,17 @@ class MWEchoNotifUser {
// Schedule an update to the echo_unread_wikis table
$user = $this->mUser;
DeferredUpdates::addCallableUpdate( function () use ( $user, $alertCount, $alertUnread, $msgCount, $msgUnread ) {
$updateCallback = 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();

View file

@ -10,7 +10,7 @@ class BackfillUnreadWikis extends Maintenance {
public function __construct() {
parent::__construct();
$this->mDescription = "Backfill echo_unread_wikis table";
$this->mDescription = "Backfill echo_unread_wikis table and recache notification counts for all users";
$this->setBatchSize( 300 );
}
@ -28,16 +28,7 @@ class BackfillUnreadWikis extends Maintenance {
$user = User::newFromRow( $row );
$notifUser = MWEchoNotifUser::newFromUser( $user );
$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 );
}
$notifUser->resetNotificationCount( DB_SLAVE, false );
}
$processed += count( $batch );