Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small cache when get user id on interation #29296

Merged
merged 3 commits into from
Feb 22, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
small cache when get user id on interation
  • Loading branch information
lunny committed Feb 21, 2024
commit a50ed118c07b2918ba7b702c2b408b33f1d656b5
12 changes: 9 additions & 3 deletions services/agit/agit.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
_, forcePush = opts.GitPushOptions["force-push"]
objectFormat, _ := gitRepo.GetObjectFormat()

users := map[int64]*user_model.User{}

for i := range opts.OldCommitIDs {
if opts.NewCommitIDs[i] == objectFormat.EmptyObjectID().String() {
results = append(results, private.HookProcReceiveRefResult{
Expand Down Expand Up @@ -116,9 +118,13 @@ func ProcReceive(ctx context.Context, repo *repo_model.Repository, gitRepo *git.
description = opts.GitPushOptions["description"]
}

pusher, err := user_model.GetUserByID(ctx, opts.UserID)
if err != nil {
return nil, fmt.Errorf("Failed to get user. Error: %w", err)
pusher, has := users[opts.UserID]
if !has {
pusher, err = user_model.GetUserByID(ctx, opts.UserID)
if err != nil {
return nil, fmt.Errorf("Failed to get user. Error: %w", err)
}
users[opts.UserID] = pusher
}

prIssue := &issues_model.Issue{
Expand Down
Loading