mirror of https://github.com/go-gitea/gitea.git
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 <git@yardenshoham.com>
This commit is contained in:
parent
116f8e12a7
commit
3af2c8e4ab
|
@ -9,7 +9,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
|
@ -579,20 +578,15 @@ func SearchRepo(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// collect the latest commit of each repo
|
// collect the latest commit of each repo
|
||||||
repoIDsToLatestCommitSHAs := make(map[int64]string)
|
// at most there are dozens of repos (limited by MaxResponseItems), so it's not a big problem at the moment
|
||||||
wg := sync.WaitGroup{}
|
repoIDsToLatestCommitSHAs := make(map[int64]string, len(repos))
|
||||||
wg.Add(len(repos))
|
|
||||||
for _, repo := range repos {
|
for _, repo := range repos {
|
||||||
go func(repo *repo_model.Repository) {
|
commitID, err := repo_service.GetBranchCommitID(ctx, repo, repo.DefaultBranch)
|
||||||
defer wg.Done()
|
if err != nil {
|
||||||
commitID, err := repo_service.GetBranchCommitID(ctx, repo, repo.DefaultBranch)
|
continue
|
||||||
if err != nil {
|
}
|
||||||
return
|
repoIDsToLatestCommitSHAs[repo.ID] = commitID
|
||||||
}
|
|
||||||
repoIDsToLatestCommitSHAs[repo.ID] = commitID
|
|
||||||
}(repo)
|
|
||||||
}
|
}
|
||||||
wg.Wait()
|
|
||||||
|
|
||||||
// call the database O(1) times to get the commit statuses for all repos
|
// call the database O(1) times to get the commit statuses for all repos
|
||||||
repoToItsLatestCommitStatuses, err := git_model.GetLatestCommitStatusForPairs(ctx, repoIDsToLatestCommitSHAs, db.ListOptions{})
|
repoToItsLatestCommitStatuses, err := git_model.GetLatestCommitStatusForPairs(ctx, repoIDsToLatestCommitSHAs, db.ListOptions{})
|
||||||
|
|
Loading…
Reference in New Issue