-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
92 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2025 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package user | ||
|
||
import ( | ||
"context" | ||
|
||
"code.gitea.io/gitea/models/db" | ||
) | ||
|
||
func GetUsersMapByIDs(ctx context.Context, userIDs []int64) (map[int64]*User, error) { | ||
userMaps := make(map[int64]*User, len(userIDs)) | ||
left := len(userIDs) | ||
for left > 0 { | ||
limit := db.DefaultMaxInSize | ||
if left < limit { | ||
limit = left | ||
} | ||
err := db.GetEngine(ctx). | ||
In("id", userIDs[:limit]). | ||
Find(&userMaps) | ||
if err != nil { | ||
return nil, err | ||
} | ||
left -= limit | ||
userIDs = userIDs[limit:] | ||
} | ||
return userMaps, nil | ||
} | ||
|
||
func GetPossibleUserFromMap(userID int64, usererMaps map[int64]*User) *User { | ||
switch userID { | ||
case GhostUserID: | ||
return NewGhostUser() | ||
case ActionsUserID: | ||
return NewActionsUser() | ||
case 0: | ||
return nil | ||
default: | ||
user, ok := usererMaps[userID] | ||
if !ok { | ||
return NewGhostUser() | ||
} | ||
return user | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters