Skip to content

Commit 3af2c8e

Browse files
Remove the parallelizing when loading repo for dashboard (#24705)
Ref: #24638 IMO, parallelizing might run out server resources more quickly. Gitea shouldn't use a lot of go-routine in a web handler. And add a comment about how many repositories there could be at most. Co-authored-by: Yarden Shoham <[email protected]>
1 parent 116f8e1 commit 3af2c8e

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

routers/web/repo/repo.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"fmt"
1010
"net/http"
1111
"strings"
12-
"sync"
1312

1413
"code.gitea.io/gitea/models"
1514
"code.gitea.io/gitea/models/db"
@@ -579,20 +578,15 @@ func SearchRepo(ctx *context.Context) {
579578
}
580579

581580
// collect the latest commit of each repo
582-
repoIDsToLatestCommitSHAs := make(map[int64]string)
583-
wg := sync.WaitGroup{}
584-
wg.Add(len(repos))
581+
// at most there are dozens of repos (limited by MaxResponseItems), so it's not a big problem at the moment
582+
repoIDsToLatestCommitSHAs := make(map[int64]string, len(repos))
585583
for _, repo := range repos {
586-
go func(repo *repo_model.Repository) {
587-
defer wg.Done()
588-
commitID, err := repo_service.GetBranchCommitID(ctx, repo, repo.DefaultBranch)
589-
if err != nil {
590-
return
591-
}
592-
repoIDsToLatestCommitSHAs[repo.ID] = commitID
593-
}(repo)
584+
commitID, err := repo_service.GetBranchCommitID(ctx, repo, repo.DefaultBranch)
585+
if err != nil {
586+
continue
587+
}
588+
repoIDsToLatestCommitSHAs[repo.ID] = commitID
594589
}
595-
wg.Wait()
596590

597591
// call the database O(1) times to get the commit statuses for all repos
598592
repoToItsLatestCommitStatuses, err := git_model.GetLatestCommitStatusForPairs(ctx, repoIDsToLatestCommitSHAs, db.ListOptions{})

0 commit comments

Comments
 (0)