UserNotificationGateway: Use batching in markRead() and markUnread()

Change-Id: I85452d0f0afe974d26a575e000f6ae2ceeddf06c
This commit is contained in:
Roan Kattouw 2018-08-09 16:33:45 -07:00
parent 397a954cf1
commit a9afcfb43a

View file

@ -51,6 +51,7 @@ class EchoUserNotificationGateway {
* failure, or when there was nothing to update
*/
public function markRead( array $eventIDs ) {
global $wgUpdateRowsPerQuery;
if ( !$eventIDs ) {
return false;
}
@ -60,16 +61,21 @@ class EchoUserNotificationGateway {
return false;
}
return $dbw->update(
$success = true;
foreach ( array_chunk( $eventIDs, $wgUpdateRowsPerQuery ) as $batch ) {
$success = $dbw->update(
self::$notificationTable,
[ 'notification_read_timestamp' => $dbw->timestamp( wfTimestampNow() ) ],
[
'notification_user' => $this->user->getId(),
'notification_event' => $eventIDs,
'notification_event' => $batch,
'notification_read_timestamp' => null,
],
__METHOD__
);
) && $success;
}
return $success;
}
/**
@ -79,26 +85,30 @@ class EchoUserNotificationGateway {
* failure, or when there was nothing to update
*/
public function markUnRead( array $eventIDs ) {
global $wgUpdateRowsPerQuery;
if ( !$eventIDs ) {
return false;
}
$dbw = $this->getDB( DB_MASTER );
return $dbw->update(
foreach ( array_chunk( $eventIDs, $wgUpdateRowsPerQuery ) as $batch ) {
$success = $dbw->update(
self::$notificationTable,
[ 'notification_read_timestamp' => null ],
[
'notification_user' => $this->user->getId(),
'notification_event' => $eventIDs,
'notification_event' => $batch,
'notification_read_timestamp IS NOT NULL'
],
__METHOD__
);
) && $success;
}
return $success;
}
/**
* Mark all notification as read, use MWEchoNotifUer::markAllRead() instead
* Mark all notification as read, use MWEchoNotifUser::markAllRead() instead
* @deprecated may need this when running in a job or revive this when we
* have updateJoin()
*/