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
10 changed files with 61 additions and 18 deletions
|
@ -60,7 +60,7 @@ func concatFields(fields watermill.LogFields) string {
|
||||||
full := ""
|
full := ""
|
||||||
|
|
||||||
for key, val := range fields {
|
for key, val := range fields {
|
||||||
full += fmt.Sprintf("%s=%s, ", key, val)
|
full += fmt.Sprintf("%s=%v, ", key, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
if full != "" {
|
if full != "" {
|
||||||
|
|
|
@ -119,10 +119,12 @@ func (b *Bucket) ReadAll(s *xorm.Session, auth web.Auth, search string, page int
|
||||||
|
|
||||||
// Get all users
|
// Get all users
|
||||||
users := make(map[int64]*user.User)
|
users := make(map[int64]*user.User)
|
||||||
|
if len(userIDs) > 0 {
|
||||||
err = s.In("id", userIDs).Find(&users)
|
err = s.In("id", userIDs).Find(&users)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, bb := range buckets {
|
for _, bb := range buckets {
|
||||||
bb.CreatedBy = users[bb.CreatedByID]
|
bb.CreatedBy = users[bb.CreatedByID]
|
||||||
|
|
|
@ -218,10 +218,12 @@ func getLabelsByTaskIDs(s *xorm.Session, opts *LabelByTaskIDsOptions) (ls []*lab
|
||||||
userids = append(userids, l.CreatedByID)
|
userids = append(userids, l.CreatedByID)
|
||||||
}
|
}
|
||||||
users := make(map[int64]*user.User)
|
users := make(map[int64]*user.User)
|
||||||
|
if len(userids) > 0 {
|
||||||
err = s.In("id", userids).Find(&users)
|
err = s.In("id", userids).Find(&users)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, 0, err
|
return nil, 0, 0, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Obfuscate all user emails
|
// Obfuscate all user emails
|
||||||
for _, u := range users {
|
for _, u := range users {
|
||||||
|
|
|
@ -182,10 +182,12 @@ func (share *LinkSharing) ReadAll(s *xorm.Session, a web.Auth, search string, pa
|
||||||
}
|
}
|
||||||
|
|
||||||
users := make(map[int64]*user.User)
|
users := make(map[int64]*user.User)
|
||||||
|
if len(userIDs) > 0 {
|
||||||
err = s.In("id", userIDs).Find(&users)
|
err = s.In("id", userIDs).Find(&users)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, 0, err
|
return nil, 0, 0, err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, s := range shares {
|
for _, s := range shares {
|
||||||
s.SharedBy = users[s.SharedByID]
|
s.SharedBy = users[s.SharedByID]
|
||||||
|
|
|
@ -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
|
// 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) {
|
func GetListsByIDs(s *xorm.Session, listIDs []int64) (lists map[int64]*List, err error) {
|
||||||
lists = make(map[int64]*List, len(listIDs))
|
lists = make(map[int64]*List, len(listIDs))
|
||||||
|
|
||||||
|
if len(listIDs) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
err = s.In("id", listIDs).Find(&lists)
|
err = s.In("id", listIDs).Find(&lists)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -405,10 +410,12 @@ func addListDetails(s *xorm.Session, lists []*List) (err error) {
|
||||||
|
|
||||||
// Get all list owners
|
// Get all list owners
|
||||||
owners := map[int64]*user.User{}
|
owners := map[int64]*user.User{}
|
||||||
|
if len(ownerIDs) > 0 {
|
||||||
err = s.In("id", ownerIDs).Find(&owners)
|
err = s.In("id", ownerIDs).Find(&owners)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var fileIDs []int64
|
var fileIDs []int64
|
||||||
for _, l := range lists {
|
for _, l := range lists {
|
||||||
|
|
|
@ -657,6 +657,13 @@ func (n *Namespace) Delete(s *xorm.Session, a web.Auth) (err error) {
|
||||||
listIDs = append(listIDs, l.ID)
|
listIDs = append(listIDs, l.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(listIDs) == 0 {
|
||||||
|
return events.Dispatch(&NamespaceDeletedEvent{
|
||||||
|
Namespace: n,
|
||||||
|
Doer: a,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Delete tasks
|
// Delete tasks
|
||||||
_, err = s.In("list_id", listIDs).Delete(&Task{})
|
_, err = s.In("list_id", listIDs).Delete(&Task{})
|
||||||
if err != nil {
|
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
|
return nil, 0, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(attachments) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
fileIDs := make([]int64, 0, len(attachments))
|
fileIDs := make([]int64, 0, len(attachments))
|
||||||
userIDs := make([]int64, 0, len(attachments))
|
userIDs := make([]int64, 0, len(attachments))
|
||||||
for _, r := range attachments {
|
for _, r := range attachments {
|
||||||
|
@ -228,10 +232,12 @@ func getTaskAttachmentsByTaskIDs(s *xorm.Session, taskIDs []int64) (attachments
|
||||||
}
|
}
|
||||||
|
|
||||||
users := make(map[int64]*user.User)
|
users := make(map[int64]*user.User)
|
||||||
|
if len(userIDs) > 0 {
|
||||||
err = s.In("id", userIDs).Find(&users)
|
err = s.In("id", userIDs).Find(&users)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Obfuscate all user emails
|
// Obfuscate all user emails
|
||||||
for _, u := range users {
|
for _, u := range users {
|
||||||
|
|
|
@ -49,6 +49,10 @@ type taskUser struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTaskUsersForTasks(s *xorm.Session, taskIDs []int64) (taskUsers []*taskUser, err error) {
|
func getTaskUsersForTasks(s *xorm.Session, taskIDs []int64) (taskUsers []*taskUser, err error) {
|
||||||
|
if len(taskIDs) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Get all creators of tasks
|
// Get all creators of tasks
|
||||||
creators := make(map[int64]*user.User, len(taskIDs))
|
creators := make(map[int64]*user.User, len(taskIDs))
|
||||||
err = s.
|
err = s.
|
||||||
|
|
|
@ -96,12 +96,20 @@ func ListUsersFromList(s *xorm.Session, l *List, search string) (users []*user.U
|
||||||
uids = append(uids, id)
|
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
|
// Get all users
|
||||||
err = s.
|
err = s.
|
||||||
Table("users").
|
Table("users").
|
||||||
Select("*").
|
Select("*").
|
||||||
In("id", uids).
|
Where(cond).
|
||||||
And("username LIKE ?", "%"+search+"%").
|
|
||||||
GroupBy("id").
|
GroupBy("id").
|
||||||
OrderBy("id").
|
OrderBy("id").
|
||||||
Find(&users)
|
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
|
// 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) {
|
func GetUsersByIDs(s *xorm.Session, userIDs []int64) (users map[int64]*User, err error) {
|
||||||
users = make(map[int64]*User)
|
users = make(map[int64]*User)
|
||||||
|
|
||||||
|
if len(userIDs) == 0 {
|
||||||
|
return users, nil
|
||||||
|
}
|
||||||
|
|
||||||
err = s.In("id", userIDs).Find(&users)
|
err = s.In("id", userIDs).Find(&users)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue