fix(reminders): make sure reminders are only sent once per user
continuous-integration/drone/push Build is failing Details

Previously, when a user was creator and assigned to a task, they would get two reminder notifications for the same task. This was caused by Vikunja first fetching all creators and then all assignees and not removing duplicates from that list.

Related: https://community.vikunja.io/t/duplicate-email-reminders/1505/3
This commit is contained in:
kolaente 2023-08-24 10:47:17 +02:00
parent 5e8084c194
commit 1b9c4204a8
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
2 changed files with 14 additions and 1 deletions

View File

@ -171,6 +171,8 @@ func getTasksWithRemindersDueAndTheirUsers(s *xorm.Session, now time.Time) (remi
usersPerTask[ur.Task.ID] = append(usersPerTask[ur.Task.ID], ur)
}
seen := make(map[int64]map[int64]bool)
// Time zone cache per time zone string to avoid parsing the same time zone over and over again
tzs := make(map[string]*time.Location)
// Figure out which reminders are actually due in the time zone of the users
@ -178,6 +180,17 @@ func getTasksWithRemindersDueAndTheirUsers(s *xorm.Session, now time.Time) (remi
for _, u := range usersPerTask[r.TaskID] {
// This ensures we send each reminder only once to each user
if seen[r.TaskID] == nil {
seen[r.Ta2skID] = make(map[int64]bool)
}
if _, exists := seen[r.TaskID][u.User.ID]; exists {
continue
}
seen[r.TaskID][u.User.ID] = true
if u.User.Timezone == "" {
u.User.Timezone = config.GetTimeZone().String()
}

View File

@ -30,7 +30,7 @@ func TestReminderGetTasksInTheNextMinute(t *testing.T) {
s := db.NewSession()
defer s.Close()
now, err := time.Parse(time.RFC3339Nano, "2018-12-01T01:13:00Z")
now, err := time.Parse(time.RFC3339Nano, "2018-12-01T01:12:00Z")
assert.NoError(t, err)
notifications, err := getTasksWithRemindersDueAndTheirUsers(s, now)
assert.NoError(t, err)