forked from vikunja/vikunja
Explicitly check if there are Ids before trying to get items by a list of Ids
This commit is contained in:
parent
3999580fe6
commit
6de3d8b3a1
@ -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 != "" {
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user