loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

related #24638

authored by

Lunny Xiao and committed by
GitHub
807c9712 640a88fa

+25 -6
+17
models/git/branch_list.go
··· 130 130 } 131 131 return branches, nil 132 132 } 133 + 134 + func FindBranchesByRepoAndBranchName(ctx context.Context, repoBranches map[int64]string) (map[int64]string, error) { 135 + cond := builder.NewCond() 136 + for repoID, branchName := range repoBranches { 137 + cond = cond.Or(builder.And(builder.Eq{"repo_id": repoID}, builder.Eq{"name": branchName})) 138 + } 139 + var branches []*Branch 140 + if err := db.GetEngine(ctx). 141 + Where(cond).Find(&branches); err != nil { 142 + return nil, err 143 + } 144 + branchMap := make(map[int64]string, len(branches)) 145 + for _, branch := range branches { 146 + branchMap[branch.RepoID] = branch.CommitID 147 + } 148 + return branchMap, nil 149 + }
+8 -6
routers/web/repo/repo.go
··· 579 579 580 580 // collect the latest commit of each repo 581 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)) 582 + repoBranchNames := make(map[int64]string, len(repos)) 583 583 for _, repo := range repos { 584 - commitID, err := repo_service.GetBranchCommitID(ctx, repo, repo.DefaultBranch) 585 - if err != nil { 586 - continue 587 - } 588 - repoIDsToLatestCommitSHAs[repo.ID] = commitID 584 + repoBranchNames[repo.ID] = repo.DefaultBranch 585 + } 586 + 587 + repoIDsToLatestCommitSHAs, err := git_model.FindBranchesByRepoAndBranchName(ctx, repoBranchNames) 588 + if err != nil { 589 + log.Error("FindBranchesByRepoAndBranchName: %v", err) 590 + return 589 591 } 590 592 591 593 // call the database O(1) times to get the commit statuses for all repos