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>
This commit is contained in:
Calvin Tjoaquinnandwxiaoguang authored and GitHub committed 2026-10-12 16:00:54 +08:00
1 parent aa32eb97fa
commit 8c7b8d085c
10 files changed
+386 -478

No files matched your search

+9 -11
View File
@@ -15,17 +15,15 @@ func GetUsersMapByIDs(ctx context.Context, userIDs []int64) (map[int64]*User, er
return userMaps, nil
}
left := len(userIDs)
for left > 0 {
limit := min(left, db.DefaultMaxInSize)
err := db.GetEngine(ctx).
In("id", userIDs[:limit]).
Find(&userMaps)
if err != nil {
return nil, err
}
left -= limit
userIDs = userIDs[limit:]
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
}