diff --git a/pkg/log/watermill_logger.go b/pkg/log/watermill_logger.go index 4a6c4e41..8f50c858 100644 --- a/pkg/log/watermill_logger.go +++ b/pkg/log/watermill_logger.go @@ -60,7 +60,7 @@ func concatFields(fields watermill.LogFields) string { full := "" for key, val := range fields { - full += fmt.Sprintf("%s=%s, ", key, val) + full += fmt.Sprintf("%s=%v, ", key, val) } if full != "" { diff --git a/pkg/models/kanban.go b/pkg/models/kanban.go index 9b6907d8..264114fd 100644 --- a/pkg/models/kanban.go +++ b/pkg/models/kanban.go @@ -119,9 +119,11 @@ func (b *Bucket) ReadAll(s *xorm.Session, auth web.Auth, search string, page int // Get all users users := make(map[int64]*user.User) - err = s.In("id", userIDs).Find(&users) - if err != nil { - return + if len(userIDs) > 0 { + err = s.In("id", userIDs).Find(&users) + if err != nil { + return + } } for _, bb := range buckets { diff --git a/pkg/models/label_task.go b/pkg/models/label_task.go index de5be5c1..5c94a5c7 100644 --- a/pkg/models/label_task.go +++ b/pkg/models/label_task.go @@ -218,9 +218,11 @@ func getLabelsByTaskIDs(s *xorm.Session, opts *LabelByTaskIDsOptions) (ls []*lab userids = append(userids, l.CreatedByID) } users := make(map[int64]*user.User) - err = s.In("id", userids).Find(&users) - if err != nil { - return nil, 0, 0, err + if len(userids) > 0 { + err = s.In("id", userids).Find(&users) + if err != nil { + return nil, 0, 0, err + } } // Obfuscate all user emails diff --git a/pkg/models/link_sharing.go b/pkg/models/link_sharing.go index 363897ab..8b7f4c76 100644 --- a/pkg/models/link_sharing.go +++ b/pkg/models/link_sharing.go @@ -182,9 +182,11 @@ func (share *LinkSharing) ReadAll(s *xorm.Session, a web.Auth, search string, pa } users := make(map[int64]*user.User) - err = s.In("id", userIDs).Find(&users) - if err != nil { - return nil, 0, 0, err + if len(userIDs) > 0 { + err = s.In("id", userIDs).Find(&users) + if err != nil { + return nil, 0, 0, err + } } for _, s := range shares { diff --git a/pkg/models/list.go b/pkg/models/list.go index 97cf5d90..118cbdc0 100644 --- a/pkg/models/list.go +++ b/pkg/models/list.go @@ -290,6 +290,11 @@ func GetListSimplByTaskID(s *xorm.Session, taskID int64) (l *List, err error) { // GetListsByIDs returns a map of lists from a slice with list ids func GetListsByIDs(s *xorm.Session, listIDs []int64) (lists map[int64]*List, err error) { lists = make(map[int64]*List, len(listIDs)) + + if len(listIDs) == 0 { + return + } + err = s.In("id", listIDs).Find(&lists) return } @@ -405,9 +410,11 @@ func addListDetails(s *xorm.Session, lists []*List) (err error) { // Get all list owners owners := map[int64]*user.User{} - err = s.In("id", ownerIDs).Find(&owners) - if err != nil { - return + if len(ownerIDs) > 0 { + err = s.In("id", ownerIDs).Find(&owners) + if err != nil { + return + } } var fileIDs []int64 diff --git a/pkg/models/namespace.go b/pkg/models/namespace.go index b61d5509..4b4c4c63 100644 --- a/pkg/models/namespace.go +++ b/pkg/models/namespace.go @@ -657,6 +657,13 @@ func (n *Namespace) Delete(s *xorm.Session, a web.Auth) (err error) { listIDs = append(listIDs, l.ID) } + if len(listIDs) == 0 { + return events.Dispatch(&NamespaceDeletedEvent{ + Namespace: n, + Doer: a, + }) + } + // Delete tasks _, err = s.In("list_id", listIDs).Delete(&Task{}) if err != nil { diff --git a/pkg/models/task_attachment.go b/pkg/models/task_attachment.go index 6d7e7092..457d16d2 100644 --- a/pkg/models/task_attachment.go +++ b/pkg/models/task_attachment.go @@ -128,6 +128,10 @@ func (ta *TaskAttachment) ReadAll(s *xorm.Session, a web.Auth, search string, pa return nil, 0, 0, err } + if len(attachments) == 0 { + return + } + fileIDs := make([]int64, 0, len(attachments)) userIDs := make([]int64, 0, len(attachments)) for _, r := range attachments { @@ -228,9 +232,11 @@ func getTaskAttachmentsByTaskIDs(s *xorm.Session, taskIDs []int64) (attachments } users := make(map[int64]*user.User) - err = s.In("id", userIDs).Find(&users) - if err != nil { - return + if len(userIDs) > 0 { + err = s.In("id", userIDs).Find(&users) + if err != nil { + return + } } // Obfuscate all user emails diff --git a/pkg/models/task_reminder.go b/pkg/models/task_reminder.go index 4746fc79..f44c7065 100644 --- a/pkg/models/task_reminder.go +++ b/pkg/models/task_reminder.go @@ -49,6 +49,10 @@ type taskUser struct { } func getTaskUsersForTasks(s *xorm.Session, taskIDs []int64) (taskUsers []*taskUser, err error) { + if len(taskIDs) == 0 { + return + } + // Get all creators of tasks creators := make(map[int64]*user.User, len(taskIDs)) err = s. diff --git a/pkg/models/user_list.go b/pkg/models/user_list.go index f1552192..b5d369b0 100644 --- a/pkg/models/user_list.go +++ b/pkg/models/user_list.go @@ -96,12 +96,20 @@ func ListUsersFromList(s *xorm.Session, l *List, search string) (users []*user.U uids = append(uids, id) } + var cond builder.Cond = builder.Like{"username", "%" + search + "%"} + + if len(uids) > 0 { + cond = builder.And( + builder.In("id", uids), + cond, + ) + } + // Get all users err = s. Table("users"). Select("*"). - In("id", uids). - And("username LIKE ?", "%"+search+"%"). + Where(cond). GroupBy("id"). OrderBy("id"). Find(&users) diff --git a/pkg/user/user.go b/pkg/user/user.go index 5a1364c7..838097e3 100644 --- a/pkg/user/user.go +++ b/pkg/user/user.go @@ -182,6 +182,11 @@ func GetUserWithEmail(s *xorm.Session, user *User) (userOut *User, err error) { // GetUsersByIDs returns a map of users from a slice of user ids func GetUsersByIDs(s *xorm.Session, userIDs []int64) (users map[int64]*User, err error) { users = make(map[int64]*User) + + if len(userIDs) == 0 { + return users, nil + } + err = s.In("id", userIDs).Find(&users) if err != nil { return