mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-30 18:45:07 +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
|
<?php
|
||||||
|
use MediaWiki\MediaWikiServices;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents the controller for moderating notifications
|
* This class represents the controller for moderating notifications
|
||||||
|
@ -23,13 +24,18 @@ class EchoModerationController {
|
||||||
$affectedUserIds = $notificationMapper->fetchUsersWithNotificationsForEvents( $eventIds );
|
$affectedUserIds = $notificationMapper->fetchUsersWithNotificationsForEvents( $eventIds );
|
||||||
$eventMapper->toggleDeleted( $eventIds, $moderate );
|
$eventMapper->toggleDeleted( $eventIds, $moderate );
|
||||||
|
|
||||||
/**
|
DeferredUpdates::addCallableUpdate( function () {
|
||||||
* Recompute the notification count for the
|
// This udate runs after than main transaction round commits.
|
||||||
* users whose notifications have been moderated.
|
// Wait for the events deletions to be propagated to replica DBs
|
||||||
*/
|
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
|
||||||
foreach ( $affectedUserIds as $userId ) {
|
$lbFactory->waitForReplication( [ 'timeout' => 5 ] );
|
||||||
$user = User::newFromId( $userId );
|
$lbFactory->flushReplicaSnapshots( __METHOD__ );
|
||||||
MWEchoNotifUser::newFromUser( $user )->resetNotificationCount( DB_MASTER );
|
// 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