Skip to content

Commit

Permalink
Remove the parallelizing when loading repo for dashboard (#24705)
Browse files Browse the repository at this point in the history
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 <git@yardenshoham.com>
  • Loading branch information
wxiaoguang and yardenshoham authored May 14, 2023
1 parent 116f8e1 commit 3af2c8e
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions routers/web/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"
"net/http"
"strings"
"sync"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
Expand Down Expand Up @@ -579,20 +578,15 @@ 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)
commitID, err := repo_service.GetBranchCommitID(ctx, repo, repo.DefaultBranch)
if err != nil {
continue
}
repoIDsToLatestCommitSHAs[repo.ID] = commitID
}
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{})
Expand Down

0 comments on commit 3af2c8e

Please sign in to comment.