fix(reactions): make retrieving reactions for tasks more efficient

This commit is contained in:
kolaente 2024-03-11 23:10:53 +01:00
parent 8af554292c
commit 69b9086bef
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 6 additions and 18 deletions

View File

@ -532,23 +532,6 @@ func addRelatedTasksToTasks(s *xorm.Session, taskIDs []int64, taskMap map[int64]
return
}
func addReactionsToTasks(s *xorm.Session, taskIDs []int64, taskMap map[int64]*Task) (err error) {
reactions, err := getReactionsForEntityIDs(s, ReactionKindTask, taskIDs)
if err != nil {
return err
}
for taskID, r := range reactions {
t, has := taskMap[taskID]
if has {
t.Reactions = r
}
}
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(s *xorm.Session, taskMap map[int64]*Task, a web.Auth) (err error) {
@ -604,7 +587,7 @@ func addMoreInfoToTasks(s *xorm.Session, taskMap map[int64]*Task, a web.Auth) (e
return err
}
err = addReactionsToTasks(s, taskIDs, taskMap)
reactions, err := getReactionsForEntityIDs(s, ReactionKindTask, taskIDs)
if err != nil {
return
}
@ -625,6 +608,11 @@ func addMoreInfoToTasks(s *xorm.Session, taskMap map[int64]*Task, a web.Auth) (e
task.setIdentifier(projects[task.ProjectID])
task.IsFavorite = taskFavorites[task.ID]
r, has := reactions[task.ID]
if has {
task.Reactions = r
}
}
// Get all related tasks