Files
gitea/models/user/user_list.go
T
Calvin Tjoaquinnandwxiaoguang 8c7b8d085c fix(models): fix incorrect or unnecessary "scan rows" (#39516)
The six batched loaders in `IssueList` iterate their rows and never call
`rows.Err()`.

Refactored the code by a new helper function.

---------

Signed-off-by: Calvin Tjoaquinn <calvintjoa23@gmail.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2026-10-12 16:00:54 +08:00

44 lines
919 B
Go

// Copyright 2025 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package user
import (
"context"
"gitea.dev/models/db"
)
func GetUsersMapByIDs(ctx context.Context, userIDs []int64) (map[int64]*User, error) {
userMaps := make(map[int64]*User, len(userIDs))
if len(userIDs) == 0 {
return userMaps, nil
}
err := db.QueryAndProcessByChunk(userIDs, func(chunk []int64) (out []*User, err error) {
err = db.GetEngine(ctx).In("id", chunk).Find(&out)
return out, err
}, func(user *User) error {
userMaps[user.ID] = user
return nil
})
if err != nil {
return nil, err
}
return userMaps, nil
}
func GetPossibleUserFromMap(userID int64, usererMaps map[int64]*User) *User {
if userID == 0 {
return nil
}
if newFunc, ok := globalVars().systemUserNewFuncs[userID]; ok {
return newFunc()
}
user, ok := usererMaps[userID]
if !ok {
return NewGhostUser()
}
return user
}