gitea源码

user_list.go 928B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright 2025 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package user
  4. import (
  5. "context"
  6. "code.gitea.io/gitea/models/db"
  7. )
  8. func GetUsersMapByIDs(ctx context.Context, userIDs []int64) (map[int64]*User, error) {
  9. userMaps := make(map[int64]*User, len(userIDs))
  10. if len(userIDs) == 0 {
  11. return userMaps, nil
  12. }
  13. left := len(userIDs)
  14. for left > 0 {
  15. limit := min(left, db.DefaultMaxInSize)
  16. err := db.GetEngine(ctx).
  17. In("id", userIDs[:limit]).
  18. Find(&userMaps)
  19. if err != nil {
  20. return nil, err
  21. }
  22. left -= limit
  23. userIDs = userIDs[limit:]
  24. }
  25. return userMaps, nil
  26. }
  27. func GetPossibleUserFromMap(userID int64, usererMaps map[int64]*User) *User {
  28. switch userID {
  29. case GhostUserID:
  30. return NewGhostUser()
  31. case ActionsUserID:
  32. return NewActionsUser()
  33. case 0:
  34. return nil
  35. default:
  36. user, ok := usererMaps[userID]
  37. if !ok {
  38. return NewGhostUser()
  39. }
  40. return user
  41. }
  42. }