Merge lp:~twom/launchpad/rescans-need-join-conditions into lp:launchpad

Proposed by Tom Wardill
Status: Merged
Merged at revision: 18872
Proposed branch: lp:~twom/launchpad/rescans-need-join-conditions
Merge into: lp:launchpad
Diff against target: 38 lines (+5/-2)
3 files modified
lib/lp/code/model/branch.py (+2/-1)
lib/lp/code/model/branchmergeproposal.py (+1/-0)
lib/lp/code/model/gitrepository.py (+2/-1)
To merge this branch: bzr merge lp:~twom/launchpad/rescans-need-join-conditions
Reviewer Review Type Date Requested Status
Colin Watson Approve
Review via email: mp+362608@code.launchpad.net

Commit message

Join the getLatest* queries to the Job table to prevent a full scan on access.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/model/branch.py'
2--- lib/lp/code/model/branch.py 2019-01-28 18:09:21 +0000
3+++ lib/lp/code/model/branch.py 2019-02-01 14:22:40 +0000
4@@ -1303,7 +1303,8 @@
5 latest_job = IStore(BranchJob).find(
6 BranchJob,
7 BranchJob.branch == self,
8- BranchJob.job_type == BranchScanJob.class_job_type).order_by(
9+ BranchJob.job_type == BranchScanJob.class_job_type,
10+ BranchJob.job == Job.id).order_by(
11 Desc(Job.date_finished)).first()
12 return latest_job
13
14
15=== modified file 'lib/lp/code/model/branchmergeproposal.py'
16--- lib/lp/code/model/branchmergeproposal.py 2019-01-31 11:33:58 +0000
17+++ lib/lp/code/model/branchmergeproposal.py 2019-02-01 14:22:40 +0000
18@@ -1231,6 +1231,7 @@
19 BranchMergeProposalJob,
20 BranchMergeProposalJob.branch_merge_proposal == self,
21 BranchMergeProposalJob.job_type == diff_type,
22+ BranchMergeProposalJob.job == Job.id,
23 ).order_by(Desc(Job.date_finished)).first()
24 if latest_preview is not None:
25 latest_preview = latest_preview.makeDerived()
26
27=== modified file 'lib/lp/code/model/gitrepository.py'
28--- lib/lp/code/model/gitrepository.py 2019-01-28 18:09:21 +0000
29+++ lib/lp/code/model/gitrepository.py 2019-02-01 14:22:40 +0000
30@@ -752,7 +752,8 @@
31 latest_job = IStore(GitJob).find(
32 GitJob,
33 GitJob.repository == self,
34- GitJob.job_type == GitRefScanJob.class_job_type).order_by(
35+ GitJob.job_type == GitRefScanJob.class_job_type,
36+ GitJob.job == Job.id).order_by(
37 Desc(Job.date_finished)).first()
38 return latest_job
39