mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-28 01:30:15 +00:00
resetNotificationCount() from replica with no lag
When notifications are being moderated, the unread count for affected users has to be recalculated. It was initially done using DB_SLAVE but it was leading to inconsistent data since that database did not know about recently deleted notifications. It was changed to DB_MASTER but it potentially led to too many queries on master. This patch tries to wait for the replica to have caught up with those changes and use it to update the unread count for the affected users. Bug: T93673 Change-Id: Ib4a845e82f686dd7ed807ab21a28490014b56604
This commit is contained in:
parent
7f24836607
commit
d7845da3f6
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
/**
|
||||
* This class represents the controller for moderating notifications
|
||||
|
@ -23,13 +24,18 @@ class EchoModerationController {
|
|||
$affectedUserIds = $notificationMapper->fetchUsersWithNotificationsForEvents( $eventIds );
|
||||
$eventMapper->toggleDeleted( $eventIds, $moderate );
|
||||
|
||||
/**
|
||||
* Recompute the notification count for the
|
||||
* users whose notifications have been moderated.
|
||||
*/
|
||||
foreach ( $affectedUserIds as $userId ) {
|
||||
$user = User::newFromId( $userId );
|
||||
MWEchoNotifUser::newFromUser( $user )->resetNotificationCount( DB_MASTER );
|
||||
}
|
||||
DeferredUpdates::addCallableUpdate( function () {
|
||||
// This udate runs after than main transaction round commits.
|
||||
// Wait for the events deletions to be propagated to replica DBs
|
||||
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
|
||||
$lbFactory->waitForReplication( [ 'timeout' => 5 ] );
|
||||
$lbFactory->flushReplicaSnapshots( __METHOD__ );
|
||||
// Recompute the notification count for the
|
||||
// users whose notifications have been moderated.
|
||||
foreach ( $affectedUserIds as $userId ) {
|
||||
$user = User::newFromId( $userId );
|
||||
MWEchoNotifUser::newFromUser( $user )->resetNotificationCount( DB_REPLICA );
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue