mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-09-30 22:26:38 +08:00
autoresearch iter 16: add batch user lookup and use it for log enrichment
enrichAccessLogsWithUsers preferred the UserService contract over the local repository — correct layering, but it looped GetUserByID and issued up to a page-size worth of separate SELECTs against w_users, while the single-query WHERE id IN variant was only reached in the no-contract fallback branch. Give the contract a GetUsersByIDs so callers can keep the layering and drop the N+1. The test asserts 1 query batched against 3 per-id, so the counting itself is checked.
This commit is contained in:
@@ -220,9 +220,11 @@ func enrichAccessLogsWithUsers(ctx context.Context, list []model.AccessLogItem)
|
||||
|
||||
userMap := make(map[uint64]repository.UserDisplayName, len(userIDs))
|
||||
if userSvc := GetUserService(ctx); userSvc != nil {
|
||||
for _, uid := range userIDs {
|
||||
if u, err := userSvc.GetUserByID(ctx, uid); err == nil && u != nil {
|
||||
userMap[uid] = repository.UserDisplayName{Username: u.Username, Nickname: u.Nickname}
|
||||
if users, err := userSvc.GetUsersByIDs(ctx, userIDs); err == nil {
|
||||
for _, u := range users {
|
||||
if u != nil {
|
||||
userMap[u.ID] = repository.UserDisplayName{Username: u.Username, Nickname: u.Nickname}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if names, err := repository.LoadUserDisplayNames(ctx, userIDs); err == nil {
|
||||
|
||||
Reference in New Issue
Block a user