From eb279fdba3651f4275106fa411e9324e9cd8145f Mon Sep 17 00:00:00 2001 From: kolaente Date: Sun, 20 Oct 2019 17:55:54 +0200 Subject: [PATCH] Refactored getting task IDs for labels --- pkg/models/label.go | 2 +- pkg/models/tasks.go | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/pkg/models/label.go b/pkg/models/label.go index b4bf2161..66841712 100644 --- a/pkg/models/label.go +++ b/pkg/models/label.go @@ -203,7 +203,7 @@ func getUserTaskIDs(u *User) (taskIDs []int64, err error) { return nil, err } - tasks, err := getTasksForLists(lists, &taskOptions{ + tasks, err := getRawTasksForLists(lists, &taskOptions{ startDate: time.Unix(0, 0), endDate: time.Unix(0, 0), sortby: SortTasksByUnsorted, diff --git a/pkg/models/tasks.go b/pkg/models/tasks.go index 7584df8a..11715902 100644 --- a/pkg/models/tasks.go +++ b/pkg/models/tasks.go @@ -184,7 +184,8 @@ type taskOptions struct { endDate time.Time } -func getTasksForLists(lists []*List, opts *taskOptions) (tasks []*Task, err error) { +func getRawTasksForLists(lists []*List, opts *taskOptions) (taskMap map[int64]*Task, err error) { + // Get all list IDs and get the tasks var listIDs []int64 for _, l := range lists { @@ -203,7 +204,7 @@ func getTasksForLists(lists []*List, opts *taskOptions) (tasks []*Task, err erro orderby = "due_date_unix asc" } - taskMap := make(map[int64]*Task) + taskMap = make(map[int64]*Task) // Then return all tasks for that lists if opts.startDate.Unix() != 0 || opts.endDate.Unix() != 0 { @@ -235,6 +236,15 @@ func getTasksForLists(lists []*List, opts *taskOptions) (tasks []*Task, err erro return nil, err } } + return +} + +func getTasksForLists(lists []*List, opts *taskOptions) (tasks []*Task, err error) { + + taskMap, err := getRawTasksForLists(lists, opts) + if err != nil { + return nil, err + } tasks, err = addMoreInfoToTasks(taskMap) if err != nil {