diff options
| author | Aleksandr Nogikh <nogikh@google.com> | 2024-01-18 16:59:40 +0100 |
|---|---|---|
| committer | Aleksandr Nogikh <nogikh@google.com> | 2024-02-05 11:12:50 +0000 |
| commit | dd7949367e116e37e692f37b90c985111178bec9 (patch) | |
| tree | f614ac6613515152f0aba37d38d11fe6fde70cdb | |
| parent | c3f154198aa4cf12b06fa6a3071b7e009d63c782 (diff) | |
dashboard: split missing backport querying
Split the single function into one that queries the information from the
DB and the one that prepares the data for the UI.
| -rw-r--r-- | dashboard/app/jobs.go | 40 | ||||
| -rw-r--r-- | dashboard/app/main.go | 30 |
2 files changed, 42 insertions, 28 deletions
diff --git a/dashboard/app/jobs.go b/dashboard/app/jobs.go index c5f50c013..0b2298364 100644 --- a/dashboard/app/jobs.go +++ b/dashboard/app/jobs.go @@ -1624,6 +1624,46 @@ func uniqueBugs(c context.Context, inBugs []*Bug, inKeys []*db.Key) ([]*Bug, []* return bugs, keys } +func relevantBackportJobs(c context.Context) ( + bugs []*Bug, jobs []*Job, jobKeys []*db.Key, err error) { + allBugs, _, bugsErr := loadAllBugs(c, func(query *db.Query) *db.Query { + return query.Filter("FixCandidateJob>", "").Filter("Status=", BugStatusOpen) + }) + if bugsErr != nil { + err = bugsErr + return + } + var allJobKeys []*db.Key + for _, bug := range allBugs { + jobKey, decodeErr := db.DecodeKey(bug.FixCandidateJob) + if decodeErr != nil { + err = decodeErr + return + } + allJobKeys = append(allJobKeys, jobKey) + } + allJobs := make([]*Job, len(allJobKeys)) + err = db.GetMulti(c, allJobKeys, allJobs) + if err != nil { + return + } + for i, job := range allJobs { + // Some assertions just in case. + jobKey := allJobKeys[i] + if !job.IsCrossTree() { + err = fmt.Errorf("job %s: expected to be cross-tree", jobKey) + return + } + if len(job.Commits) != 1 || job.InvalidatedBy != "" { + continue + } + bugs = append(bugs, allBugs[i]) + jobs = append(jobs, job) + jobKeys = append(jobKeys, jobKey) + } + return +} + type bugJobs struct { list []*bugJob } diff --git a/dashboard/app/main.go b/dashboard/app/main.go index 0af5655d4..2a95cd4fc 100644 --- a/dashboard/app/main.go +++ b/dashboard/app/main.go @@ -748,39 +748,13 @@ type rawBackport struct { } func loadAllBackports(c context.Context) ([]*rawBackport, error) { - bugs, _, err := loadAllBugs(c, func(query *db.Query) *db.Query { - return query.Filter("FixCandidateJob>", "").Filter("Status=", BugStatusOpen) - }) + bugs, jobs, _, err := relevantBackportJobs(c) if err != nil { return nil, err } - - var jobKeys []*db.Key - var jobBugs []*Bug - for _, bug := range bugs { - jobKey, err := db.DecodeKey(bug.FixCandidateJob) - if err != nil { - return nil, err - } - jobKeys = append(jobKeys, jobKey) - jobBugs = append(jobBugs, bug) - } - - jobs := make([]*Job, len(jobKeys)) - if err := db.GetMulti(c, jobKeys, jobs); err != nil { - return nil, err - } - var ret []*rawBackport perCommit := map[string]*rawBackport{} for i, job := range jobs { - // Some assertions just in case. - if !job.IsCrossTree() { - return nil, fmt.Errorf("job %s: expected to be cross-tree", jobKeys[i]) - } - if len(job.Commits) != 1 || job.InvalidatedBy != "" { - continue - } jobCommit := job.Commits[0] to := &uiRepo{URL: job.MergeBaseRepo, Branch: job.MergeBaseBranch} from := &uiRepo{URL: job.KernelRepo, Branch: job.KernelBranch} @@ -803,7 +777,7 @@ func loadAllBackports(c context.Context) ([]*rawBackport, error) { ret = append(ret, backport) perCommit[hash] = backport } - backport.Bugs = append(backport.Bugs, jobBugs[i]) + backport.Bugs = append(backport.Bugs, bugs[i]) } return ret, nil } |
