From cfb15a27f08aa50844ef155fd2c95debc258a06b Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 2 Feb 2021 23:10:50 +0100 Subject: [PATCH] Fix getting labels, lists or teams if none are available --- pkg/models/label_task.go | 4 ++++ pkg/models/list.go | 8 ++++++++ pkg/models/namespace.go | 8 ++++++++ pkg/models/teams.go | 5 +++++ 4 files changed, 25 insertions(+) diff --git a/pkg/models/label_task.go b/pkg/models/label_task.go index a23cb5163..de5be5c1f 100644 --- a/pkg/models/label_task.go +++ b/pkg/models/label_task.go @@ -208,6 +208,10 @@ func getLabelsByTaskIDs(s *xorm.Session, opts *LabelByTaskIDsOptions) (ls []*lab return nil, 0, 0, err } + if len(labels) == 0 { + return nil, 0, 0, nil + } + // Get all created by users var userids []int64 for _, l := range labels { diff --git a/pkg/models/list.go b/pkg/models/list.go index 4a1616d87..6d65af10d 100644 --- a/pkg/models/list.go +++ b/pkg/models/list.go @@ -389,6 +389,10 @@ func getRawListsForUser(s *xorm.Session, opts *listOptions) (lists []*List, resu // addListDetails adds owner user objects and list tasks to all lists in the slice func addListDetails(s *xorm.Session, lists []*List) (err error) { + if len(lists) == 0 { + return + } + var ownerIDs []int64 for _, l := range lists { ownerIDs = append(ownerIDs, l.OwnerID) @@ -412,6 +416,10 @@ func addListDetails(s *xorm.Session, lists []*List) (err error) { fileIDs = append(fileIDs, l.BackgroundFileID) } + if len(fileIDs) == 0 { + return + } + // Unsplash background file info us := []*UnsplashPhoto{} err = s.In("file_id", fileIDs).Find(&us) diff --git a/pkg/models/namespace.go b/pkg/models/namespace.go index 40460ae85..7f4f00c36 100644 --- a/pkg/models/namespace.go +++ b/pkg/models/namespace.go @@ -531,6 +531,14 @@ func (n *Namespace) Delete(s *xorm.Session, a web.Auth) (err error) { if err != nil { return } + + if len(lists) == 0 { + return events.Dispatch(&NamespaceDeletedEvent{ + Namespace: n, + Doer: a, + }) + } + var listIDs []int64 // We need to do that for here because we need the list ids to delete two times: // 1) to delete the lists itself diff --git a/pkg/models/teams.go b/pkg/models/teams.go index afa1c6ce6..e0727721b 100644 --- a/pkg/models/teams.go +++ b/pkg/models/teams.go @@ -120,6 +120,11 @@ func GetTeamByID(s *xorm.Session, id int64) (team *Team, err error) { } func addMoreInfoToTeams(s *xorm.Session, teams []*Team) (err error) { + + if len(teams) == 0 { + return nil + } + // Put the teams in a map to make assigning more info to it more efficient teamMap := make(map[int64]*Team, len(teams)) var teamIDs []int64