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

@ -43,7 +43,7 @@ type TaskAssigneeWithUser struct {
}
func getRawTaskAssigneesForTasks(taskIDs []int64) (taskAssignees []*TaskAssigneeWithUser, err error) {
taskAssignees = []*TaskAssigneeWithUser{nil}
taskAssignees = []*TaskAssigneeWithUser{}
err = x.Table("task_assignees").
Select("task_id, users.*").
In("task_id", taskIDs).
@ -55,6 +55,17 @@ func getRawTaskAssigneesForTasks(taskIDs []int64) (taskAssignees []*TaskAssignee
// Create or update a bunch of task assignees
func (t *Task) updateTaskAssignees(assignees []*User) (err error) {
// Load the current assignees
currentAssignees, err := getRawTaskAssigneesForTasks([]int64{t.ID})
if err != nil {
return err
}
t.Assignees = make([]*User, 0, len(currentAssignees))
for _, assignee := range currentAssignees {
t.Assignees = append(t.Assignees, &assignee.User)
}
// If we don't have any new assignees, delete everything right away. Saves us some hassle.
if len(assignees) == 0 && len(t.Assignees) > 0 {
_, err = x.Where("task_id = ?", t.ID).