Performance improvements when updating task assignees, do less unnessecary stuff
the build failed
Details
the build failed
Details
This commit is contained in:
parent
31c39388f1
commit
fa748328ba
|
@ -130,12 +130,11 @@ GET http://localhost:8080/api/v1/tasks/caldav
|
|||
###
|
||||
|
||||
# Update a task
|
||||
POST http://localhost:8080/api/v1/tasks/1
|
||||
POST http://localhost:8080/api/v1/tasks/3565
|
||||
Authorization: Bearer {{auth_token}}
|
||||
Content-Type: application/json
|
||||
|
||||
{"assignees":[
|
||||
{"id": 1}
|
||||
]}
|
||||
|
||||
###
|
||||
|
|
|
@ -147,22 +147,40 @@ func updateDone(oldTask *ListTask, newTask *ListTask) {
|
|||
// Create a bunch of task assignees
|
||||
func (t *ListTask) updateTaskAssignees(assignees []*User) (err error) {
|
||||
|
||||
// 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).
|
||||
Delete(ListTaskAssginee{})
|
||||
return err
|
||||
}
|
||||
|
||||
// If we didn't change anything (from 0 to zero) don't do anything.
|
||||
if len(assignees) == 0 && len(t.Assignees) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Make a hashmap of the new assignees for easier comparision
|
||||
newAssignees := make(map[int64]*User, len(assignees))
|
||||
for _, newAssignee := range assignees {
|
||||
newAssignees[newAssignee.ID] = newAssignee
|
||||
}
|
||||
|
||||
// Get old assignees to delete
|
||||
var found bool
|
||||
var assigneesToDelete []int64
|
||||
oldAssignees := make(map[int64]*User, len(t.Assignees))
|
||||
for _, oldAssignee := range t.Assignees {
|
||||
found = false
|
||||
for _, newAssignee := range assignees {
|
||||
if newAssignee.ID == oldAssignee.ID {
|
||||
found = true // If a new assignee is already in the list with old assignees
|
||||
break
|
||||
}
|
||||
if newAssignees[oldAssignee.ID] != nil {
|
||||
found = true // If a new assignee is already in the list with old assignees
|
||||
}
|
||||
|
||||
// Put all assignees which are only on the old list to the trash
|
||||
if !found {
|
||||
assigneesToDelete = append(assigneesToDelete, oldAssignee.ID)
|
||||
}
|
||||
|
||||
oldAssignees[oldAssignee.ID] = oldAssignee
|
||||
}
|
||||
|
||||
// Delete all assignees not passed
|
||||
|
@ -177,20 +195,17 @@ func (t *ListTask) updateTaskAssignees(assignees []*User) (err error) {
|
|||
|
||||
// Get the list to perform later checks
|
||||
list := List{ID: t.ListID}
|
||||
err = list.ReadOne()
|
||||
err = list.GetSimpleByID()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Loop through our users and add them
|
||||
AddNewAssignee:
|
||||
for _, u := range assignees {
|
||||
// Check if the user is already assigned and assign him only if not
|
||||
for _, oldAssignee := range t.Assignees {
|
||||
if oldAssignee.ID == u.ID {
|
||||
// continue outer loop
|
||||
continue AddNewAssignee
|
||||
}
|
||||
if oldAssignees[u.ID] != nil {
|
||||
// continue outer loop
|
||||
continue
|
||||
}
|
||||
|
||||
// Check if the user exists and has access to the list
|
||||
|
|
Loading…
Reference in New Issue