From bf243e077828a86e630d751031046f96530dcdb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 7 Apr 2025 10:05:27 -0400 Subject: [PATCH] fix: notifications.markAllRead so that it actually marks all notifications read instead of the most recent 100. if you had more than 100 unread it required clicking multiple times. also don't use markReadMultiple since we are clearing them all. --- src/notifications.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/notifications.js b/src/notifications.js index 7f7bb5268a..df7cf51fb4 100644 --- a/src/notifications.js +++ b/src/notifications.js @@ -383,8 +383,17 @@ Notifications.markReadMultiple = async function (nids, uid) { }; Notifications.markAllRead = async function (uid) { - const nids = await db.getSortedSetRevRange(`uid:${uid}:notifications:unread`, 0, 99); - await Notifications.markReadMultiple(nids, uid); + await batch.processSortedSet(`uid:${uid}:notifications:unread`, async (unreadNotifs) => { + const nids = unreadNotifs.map(n => n && n.value); + const datetimes = unreadNotifs.map(n => n && n.score); + await Promise.all([ + db.sortedSetRemove(`uid:${uid}:notifications:unread`, nids), + db.sortedSetAdd(`uid:${uid}:notifications:read`, datetimes, nids), + ]); + }, { + withScores: true, + batch: 500, + }); }; Notifications.prune = async function () {