1
0

Fixed a bug where adding assignees or reminders via an update would re-create them and not respect already inserted ones, leaving a lot of garbage

This commit is contained in:
kolaente
2019-11-03 23:08:26 +01:00
parent 9be5ab248c
commit c203d73b33
2 changed files with 30 additions and 3 deletions

View File

@ -369,6 +369,12 @@ func GetTasksByUIDs(uids []string) (tasks []*Task, err error) {
return
}
func getRemindersForTasks(taskIDs []int64) (reminders []*TaskReminder, err error) {
reminders = []*TaskReminder{}
err = x.Table("task_reminders").In("task_id", taskIDs).Find(&reminders)
return
}
// This function takes a map with pointers and returns a slice with pointers to tasks
// It adds more stuff like assignees/labels/etc to a bunch of tasks
func addMoreInfoToTasks(taskMap map[int64]*Task) (tasks []*Task, err error) {
@ -456,8 +462,7 @@ func addMoreInfoToTasks(taskMap map[int64]*Task) (tasks []*Task, err error) {
}
// Get all reminders and put them in a map to have it easier later
reminders := []*TaskReminder{}
err = x.Table("task_reminders").In("task_id", taskIDs).Find(&reminders)
reminders, err := getRemindersForTasks(taskIDs)
if err != nil {
return
}
@ -730,6 +735,17 @@ func updateDone(oldTask *Task, newTask *Task) {
// The parameter is a slice with unix dates which holds the new reminders.
func (t *Task) updateReminders(reminders []int64) (err error) {
// Load the current reminders
taskReminders, err := getRemindersForTasks([]int64{t.ID})
if err != nil {
return err
}
t.RemindersUnix = make([]int64, 0, len(taskReminders))
for _, reminder := range taskReminders {
t.RemindersUnix = append(t.RemindersUnix, reminder.ReminderUnix)
}
// If we're removing everything, delete all reminders right away
if len(reminders) == 0 && len(t.RemindersUnix) > 0 {
_, err = x.Where("task_id = ?", t.ID).