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. ---------
Showing the changes to models/git/commit_status.go (1 of 6 files). Show all
Unified · Split
| @@ -257,30 +257,27 @@ func GetLatestCommitStatus(ctx context.Context, repoID int64, sha string, listOp · 256 unmodified lines | ||
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | // 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) { | |
| 261 | 261 | type result struct { |
| 262 | 262 | Index int64 |
| 263 | 263 | RepoID int64 |
| 264 | + SHA string | |
| 264 | 265 | } |
| 265 | 266 | |
| 266 | − results := make([]result, 0, len(repoIDsToLatestCommitSHAs)) | |
| 267 | + results := make([]result, 0, len(repoSHAs)) | |
| 267 | 268 | |
| 268 | 269 | getBase := func() *xorm.Session { |
| 269 | 270 | return db.GetEngine(ctx).Table(&CommitStatus{}) |
| 270 | 271 | } |
| 271 | 272 | |
| 272 | 273 | // 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}) | |
| 276 | 277 | } |
| 277 | 278 | 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") | |
| 284 | 281 | |
| 285 | 282 | err := sess.Find(&results) |
| 286 | 283 | if err != nil { |
| @@ -297,7 +294,7 @@ func GetLatestCommitStatusForPairs(ctx context.Context, repoIDsToLatestCommitSHA · 10 unmodified lines | ||
| 297 | 294 | cond := builder.Eq{ |
| 298 | 295 | "`index`": result.Index, |
| 299 | 296 | "repo_id": result.RepoID, |
| 300 | − "sha": repoIDsToLatestCommitSHAs[result.RepoID], | |
| 297 | + "sha": result.SHA, | |
| 301 | 298 | } |
| 302 | 299 | conds = append(conds, cond) |
| 303 | 300 | } |