fix(positions): directly look in the database to fetch tasks when recalculating their position

This commit is contained in:
kolaente 2024-10-31 19:02:15 +01:00
parent d7eff8e43b
commit d03f9c7b73
No known key found for this signature in database
GPG Key ID: F40E70337AB24C9B
1 changed files with 27 additions and 9 deletions

View File

@ -117,6 +117,20 @@ func RecalculateTaskPositions(s *xorm.Session, view *ProjectView, a web.Auth) (e
log.Debugf("Recalculating task positions for view %d", view.ID)
opts := &taskSearchOptions{
sortby: []*sortParam{
{
projectViewID: view.ID,
sortBy: taskPropertyPosition,
orderBy: orderAscending,
},
{
sortBy: taskPropertyID,
orderBy: orderAscending,
},
},
}
// Using the collection so that we get all tasks, even in cases where we're dealing with a saved filter underneath
tc := &TaskCollection{
ProjectID: view.ProjectID,
@ -130,17 +144,21 @@ func RecalculateTaskPositions(s *xorm.Session, view *ProjectView, a web.Auth) (e
return err
}
opts := &taskSearchOptions{
sortby: []*sortParam{
{
projectViewID: view.ID,
sortBy: taskPropertyPosition,
orderBy: orderAscending,
},
},
for _, p := range projects {
opts.projectIDs = append(opts.projectIDs, p.ID)
}
allTasks, _, _, err := getRawTasksForProjects(s, projects, a, opts)
dbSearcher := &dbTaskSearcher{
s: s,
a: a,
}
// We're directly using the db here, even if Typesense is configured, because in some edge cases Typesense
// does not know about all tasks. These tasks then won't have their position recalculated, which means they will
// seemingly jump around after reloading their project.
// The real fix here is of course to make sure all tasks are indexed in Typesense, but until that's fixed,
// this solves the issue of task positions not being saved.
allTasks, _, err := dbSearcher.Search(opts)
if err != nil {
return
}