From fc539ef2184218f3be6060383424706e3bb1c2d6 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sun, 14 May 2023 10:51:47 +0800 Subject: [PATCH 1/3] fix --- routers/web/repo/repo.go | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index f697d9433e15..29138eecd92f 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -9,7 +9,6 @@ import ( "fmt" "net/http" "strings" - "sync" "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" @@ -579,20 +578,11 @@ func SearchRepo(ctx *context.Context) { } // collect the latest commit of each repo - repoIDsToLatestCommitSHAs := make(map[int64]string) - wg := sync.WaitGroup{} - wg.Add(len(repos)) + // at most there are dozens of repos (limited by MaxResponseItems), so it's not a big problem at the moment + repoIDsToLatestCommitSHAs := make(map[int64]string, len(repos)) for _, repo := range repos { - go func(repo *repo_model.Repository) { - defer wg.Done() - commitID, err := repo_service.GetBranchCommitID(ctx, repo, repo.DefaultBranch) - if err != nil { - return - } - repoIDsToLatestCommitSHAs[repo.ID] = commitID - }(repo) + repoIDsToLatestCommitSHAs[repo.ID], _ = repo_service.GetBranchCommitID(ctx, repo, repo.DefaultBranch) } - wg.Wait() // call the database O(1) times to get the commit statuses for all repos repoToItsLatestCommitStatuses, err := git_model.GetLatestCommitStatusForPairs(ctx, repoIDsToLatestCommitSHAs, db.ListOptions{}) From b7aac1d67208348132171ed278d9345e0a20d0d5 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sun, 14 May 2023 16:10:27 +0800 Subject: [PATCH 2/3] Update routers/web/repo/repo.go Co-authored-by: Yarden Shoham --- routers/web/repo/repo.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index 29138eecd92f..07e0dbe38a82 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -581,7 +581,11 @@ func SearchRepo(ctx *context.Context) { // at most there are dozens of repos (limited by MaxResponseItems), so it's not a big problem at the moment repoIDsToLatestCommitSHAs := make(map[int64]string, len(repos)) for _, repo := range repos { - repoIDsToLatestCommitSHAs[repo.ID], _ = repo_service.GetBranchCommitID(ctx, repo, repo.DefaultBranch) + commitID, err := repo_service.GetBranchCommitID(ctx, repo, repo.DefaultBranch) + if err != nil { + continue + } + repoIDsToLatestCommitSHAs[repo.ID] = commitID } // call the database O(1) times to get the commit statuses for all repos From 95fb06ab5bbce2fd9ab8234d672e7d483b15126e Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sun, 14 May 2023 20:09:30 +0800 Subject: [PATCH 3/3] Update routers/web/repo/repo.go Co-authored-by: Yarden Shoham --- routers/web/repo/repo.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index 07e0dbe38a82..8944890f6ad0 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -583,7 +583,7 @@ func SearchRepo(ctx *context.Context) { for _, repo := range repos { commitID, err := repo_service.GetBranchCommitID(ctx, repo, repo.DefaultBranch) if err != nil { - continue + continue } repoIDsToLatestCommitSHAs[repo.ID] = commitID }