summaryrefslogtreecommitdiffstats
path: root/routers/web
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2024-03-20 18:34:40 +0800
committerGitHub <noreply@github.com>2024-03-20 10:34:40 +0000
commit3fd15aeff2fc65479bffa5b9914e8a607c95f70e (patch)
treea3676bd79f0dc6fb85eab4e771a32dc31a562ba0 /routers/web
parent087308822392966b393e7ee2a28d406cc3e3adec (diff)
downloadgitea-3fd15aeff2fc65479bffa5b9914e8a607c95f70e.tar.gz
gitea-3fd15aeff2fc65479bffa5b9914e8a607c95f70e.zip
Add cache for dashbaord commit status (#29932)
backport #29444
Diffstat (limited to 'routers/web')
-rw-r--r--routers/web/repo/repo.go28
1 files changed, 8 insertions, 20 deletions
diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go
index 715ce34e64..5d8470e040 100644
--- a/routers/web/repo/repo.go
+++ b/routers/web/repo/repo.go
@@ -34,6 +34,7 @@ import (
"code.gitea.io/gitea/services/forms"
repo_service "code.gitea.io/gitea/services/repository"
archiver_service "code.gitea.io/gitea/services/repository/archiver"
+ commitstatus_service "code.gitea.io/gitea/services/repository/commitstatus"
)
const (
@@ -596,30 +597,14 @@ func SearchRepo(ctx *context.Context) {
ctx.SetTotalCountHeader(count)
- // collect the latest commit of each repo
- // at most there are dozens of repos (limited by MaxResponseItems), so it's not a big problem at the moment
- repoBranchNames := make(map[int64]string, len(repos))
- for _, repo := range repos {
- repoBranchNames[repo.ID] = repo.DefaultBranch
- }
-
- repoIDsToLatestCommitSHAs, err := git_model.FindBranchesByRepoAndBranchName(ctx, repoBranchNames)
+ latestCommitStatuses, err := commitstatus_service.FindReposLastestCommitStatuses(ctx, repos)
if err != nil {
- log.Error("FindBranchesByRepoAndBranchName: %v", err)
- return
- }
-
- // call the database O(1) times to get the commit statuses for all repos
- repoToItsLatestCommitStatuses, err := git_model.GetLatestCommitStatusForPairs(ctx, repoIDsToLatestCommitSHAs, db.ListOptions{})
- if err != nil {
- log.Error("GetLatestCommitStatusForPairs: %v", err)
+ log.Error("FindReposLastestCommitStatuses: %v", err)
return
}
results := make([]*repo_service.WebSearchRepository, len(repos))
for i, repo := range repos {
- latestCommitStatus := git_model.CalcCommitStatus(repoToItsLatestCommitStatuses[repo.ID])
-
results[i] = &repo_service.WebSearchRepository{
Repository: &api.Repository{
ID: repo.ID,
@@ -633,8 +618,11 @@ func SearchRepo(ctx *context.Context) {
Link: repo.Link(),
Internal: !repo.IsPrivate && repo.Owner.Visibility == api.VisibleTypePrivate,
},
- LatestCommitStatus: latestCommitStatus,
- LocaleLatestCommitStatus: latestCommitStatus.LocaleString(ctx.Locale),
+ }
+
+ if latestCommitStatuses[i] != nil {
+ results[i].LatestCommitStatus = latestCommitStatuses[i]
+ results[i].LocaleLatestCommitStatus = latestCommitStatuses[i].LocaleString(ctx.Locale)
}
}