From 9d1c72ae7c388f7f588c25d249b44cf2a3d633e4 Mon Sep 17 00:00:00 2001 From: kiatt210 <40639725+kiatt210@users.noreply.github.com> Date: Sun, 23 Jun 2024 09:50:10 +0200 Subject: [PATCH] Fix web notification icon not updated once you read all notifications (#31447) Fix #29065 Remove status filtering from GetUIDsAndNotificationCounts sql. --------- Co-authored-by: kiatt210 Co-authored-by: wxiaoguang (cherry picked from commit 6a96deb5898745d957ffd7860b2b6821c673e907) --- models/activities/notification.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/models/activities/notification.go b/models/activities/notification.go index 8e2b6d6937..09cc640224 100644 --- a/models/activities/notification.go +++ b/models/activities/notification.go @@ -287,13 +287,14 @@ type UserIDCount struct { Count int64 } -// GetUIDsAndNotificationCounts between the two provided times +// GetUIDsAndNotificationCounts returns the unread counts for every user between the two provided times. +// It must return all user IDs which appear during the period, including count=0 for users who have read all. func GetUIDsAndNotificationCounts(ctx context.Context, since, until timeutil.TimeStamp) ([]UserIDCount, error) { - sql := `SELECT user_id, count(*) AS count FROM notification ` + + sql := `SELECT user_id, sum(case when status= ? then 1 else 0 end) AS count FROM notification ` + `WHERE user_id IN (SELECT user_id FROM notification WHERE updated_unix >= ? AND ` + - `updated_unix < ?) AND status = ? GROUP BY user_id` + `updated_unix < ?) GROUP BY user_id` var res []UserIDCount - return res, db.GetEngine(ctx).SQL(sql, since, until, NotificationStatusUnread).Find(&res) + return res, db.GetEngine(ctx).SQL(sql, NotificationStatusUnread, since, until).Find(&res) } // SetIssueReadBy sets issue to be read by given user.