mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-05 07:26:36 +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:
@@ -62,6 +62,18 @@ func (s *userServiceImpl) GetUserByID(ctx context.Context, id uint64) (*contract
|
||||
return toUserDTO(u), nil
|
||||
}
|
||||
|
||||
func (s *userServiceImpl) GetUsersByIDs(ctx context.Context, ids []uint64) ([]*contracts.UserDTO, error) {
|
||||
users, err := GetUsersByIDs(ctx, ids)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
dtos := make([]*contracts.UserDTO, 0, len(users))
|
||||
for i := range users {
|
||||
dtos = append(dtos, toUserDTO(&users[i]))
|
||||
}
|
||||
return dtos, nil
|
||||
}
|
||||
|
||||
func (s *userServiceImpl) GetUserByUsername(ctx context.Context, username string) (*contracts.UserDTO, error) {
|
||||
u, err := GetUserByUsername(ctx, username)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user