History

Add commit status summary table to reduce query from commit status table (#30223)

This PR adds a new table named commit status summary to reduce queries from the commit status table. After this change, commit status summary table will be used for the final result, commit status table will be for details. ---------

Lunny Xiao committed 2 years ago

Commit 64957411 parent 5a10eec6 files · +162 −19Browse files

Showing the changes to models/git/commit_status.go (1 of 6 files). Show all

Unified · Split

models/git/commit_status.go+9−12
@@ -257,30 +257,27 @@ func GetLatestCommitStatus(ctx context.Context, repoID int64, sha string, listOp · 256 unmodified lines
257257 }
258258
259259 // GetLatestCommitStatusForPairs returns all statuses with a unique context for a given list of repo-sha pairs
260−func GetLatestCommitStatusForPairs(ctx context.Context, repoIDsToLatestCommitSHAs map[int64]string, listOptions db.ListOptions) (map[int64][]*CommitStatus, error) {
260+func GetLatestCommitStatusForPairs(ctx context.Context, repoSHAs []RepoSHA) (map[int64][]*CommitStatus, error) {
261261 type result struct {
262262 Index int64
263263 RepoID int64
264+ SHA string
264265 }
265266
266− results := make([]result, 0, len(repoIDsToLatestCommitSHAs))
267+ results := make([]result, 0, len(repoSHAs))
267268
268269 getBase := func() *xorm.Session {
269270 return db.GetEngine(ctx).Table(&CommitStatus{})
270271 }
271272
272273 // Create a disjunction of conditions for each repoID and SHA pair
273− conds := make([]builder.Cond, 0, len(repoIDsToLatestCommitSHAs))
274− for repoID, sha := range repoIDsToLatestCommitSHAs {
275− conds = append(conds, builder.Eq{"repo_id": repoID, "sha": sha})
274+ conds := make([]builder.Cond, 0, len(repoSHAs))
275+ for _, repoSHA := range repoSHAs {
276+ conds = append(conds, builder.Eq{"repo_id": repoSHA.RepoID, "sha": repoSHA.SHA})
276277 }
277278 sess := getBase().Where(builder.Or(conds...)).
278− Select("max( `index` ) as `index`, repo_id").
279− GroupBy("context_hash, repo_id").OrderBy("max( `index` ) desc")
280−
281− if !listOptions.IsListAll() {
282− sess = db.SetSessionPagination(sess, &listOptions)
283− }
279+ Select("max( `index` ) as `index`, repo_id, sha").
280+ GroupBy("context_hash, repo_id, sha").OrderBy("max( `index` ) desc")
284281
285282 err := sess.Find(&results)
286283 if err != nil {
@@ -297,7 +294,7 @@ func GetLatestCommitStatusForPairs(ctx context.Context, repoIDsToLatestCommitSHA · 10 unmodified lines
297294 cond := builder.Eq{
298295 "`index`": result.Index,
299296 "repo_id": result.RepoID,
300− "sha": repoIDsToLatestCommitSHAs[result.RepoID],
297+ "sha": result.SHA,
301298 }
302299 conds = append(conds, cond)
303300 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t