fix(filter): correctly create task positions during filter creation

This fixes a bug where a saved filter would contain many "dead" entries for tasks which are not part of that filter. These entries were "dead" because the filter would not match for them and thus they were not shown.
The problem was caused by a routine during the creation of the filter where all projects from all matching tasks would be used as input for fetching the tasks to add to task_positions.

https://community.vikunja.io/t/not-able-to-move-task-between-buckets-within-a-kanban-view-for-saved-filter/2882/3
This commit is contained in:
kolaente
2024-12-09 19:21:13 +01:00
parent 942c2e4af6
commit 25fd0f6108
2 changed files with 14 additions and 1 deletions

View File

@@ -137,6 +137,19 @@ func RecalculateTaskPositions(s *xorm.Session, view *ProjectView, a web.Auth) (e
}
if view.ProjectID < -1 {
tc.ProjectID = 0
sf, err := getSavedFilterSimpleByID(s, getSavedFilterIDFromProjectID(view.ProjectID))
if err != nil {
return err
}
opts.filterIncludeNulls = sf.Filters.FilterIncludeNulls
opts.filterTimezone = sf.Filters.FilterTimezone
opts.filter = sf.Filters.Filter
opts.parsedFilters, err = getTaskFiltersFromFilterString(opts.filter, opts.filterTimezone)
if err != nil {
return err
}
}
projects, err := getRelevantProjectsFromCollection(s, a, tc)

View File

@@ -310,7 +310,7 @@ func getRawTasksForProjects(s *xorm.Session, projects []*Project, a web.Auth, op
}
origOpts := clone.Clone(opts)
tasks, totalItems, err = tsSearcher.Search(opts)
// It is possible that project views are not yet in Typesnse's index. This causes the query here to fail.
// It is possible that project views are not yet in Typesense's index. This causes the query here to fail.
// To avoid crashing everything, we fall back to the db search in that case.
var tsErr = &typesense.HTTPError{}
if err != nil && errors.As(err, &tsErr) && tsErr.Status == 404 {