1
0
Fork 0
forked from forgejo/forgejo

Get latest commit statuses from database instead of git data on dashboard for repositories (#25605)

related #24638
This commit is contained in:
Lunny Xiao 2023-07-03 09:53:05 +08:00 committed by GitHub
parent 640a88fa09
commit 807c9712ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 6 deletions

View file

@ -579,13 +579,15 @@ func SearchRepo(ctx *context.Context) {
// 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
repoIDsToLatestCommitSHAs := make(map[int64]string, len(repos))
repoBranchNames := make(map[int64]string, len(repos))
for _, repo := range repos {
commitID, err := repo_service.GetBranchCommitID(ctx, repo, repo.DefaultBranch)
if err != nil {
continue
}
repoIDsToLatestCommitSHAs[repo.ID] = commitID
repoBranchNames[repo.ID] = repo.DefaultBranch
}
repoIDsToLatestCommitSHAs, err := git_model.FindBranchesByRepoAndBranchName(ctx, repoBranchNames)
if err != nil {
log.Error("FindBranchesByRepoAndBranchName: %v", err)
return
}
// call the database O(1) times to get the commit statuses for all repos