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 (community) 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
=== modified file 'lib/lp/code/model/branch.py'
--- lib/lp/code/model/branch.py 2019-01-28 18:09:21 +0000
+++ lib/lp/code/model/branch.py 2019-02-01 14:22:40 +0000
@@ -1303,7 +1303,8 @@
1303 latest_job = IStore(BranchJob).find(1303 latest_job = IStore(BranchJob).find(
1304 BranchJob,1304 BranchJob,
1305 BranchJob.branch == self,1305 BranchJob.branch == self,
1306 BranchJob.job_type == BranchScanJob.class_job_type).order_by(1306 BranchJob.job_type == BranchScanJob.class_job_type,
1307 BranchJob.job == Job.id).order_by(
1307 Desc(Job.date_finished)).first()1308 Desc(Job.date_finished)).first()
1308 return latest_job1309 return latest_job
13091310
13101311
=== modified file 'lib/lp/code/model/branchmergeproposal.py'
--- lib/lp/code/model/branchmergeproposal.py 2019-01-31 11:33:58 +0000
+++ lib/lp/code/model/branchmergeproposal.py 2019-02-01 14:22:40 +0000
@@ -1231,6 +1231,7 @@
1231 BranchMergeProposalJob,1231 BranchMergeProposalJob,
1232 BranchMergeProposalJob.branch_merge_proposal == self,1232 BranchMergeProposalJob.branch_merge_proposal == self,
1233 BranchMergeProposalJob.job_type == diff_type,1233 BranchMergeProposalJob.job_type == diff_type,
1234 BranchMergeProposalJob.job == Job.id,
1234 ).order_by(Desc(Job.date_finished)).first()1235 ).order_by(Desc(Job.date_finished)).first()
1235 if latest_preview is not None:1236 if latest_preview is not None:
1236 latest_preview = latest_preview.makeDerived()1237 latest_preview = latest_preview.makeDerived()
12371238
=== modified file 'lib/lp/code/model/gitrepository.py'
--- lib/lp/code/model/gitrepository.py 2019-01-28 18:09:21 +0000
+++ lib/lp/code/model/gitrepository.py 2019-02-01 14:22:40 +0000
@@ -752,7 +752,8 @@
752 latest_job = IStore(GitJob).find(752 latest_job = IStore(GitJob).find(
753 GitJob,753 GitJob,
754 GitJob.repository == self,754 GitJob.repository == self,
755 GitJob.job_type == GitRefScanJob.class_job_type).order_by(755 GitJob.job_type == GitRefScanJob.class_job_type,
756 GitJob.job == Job.id).order_by(
756 Desc(Job.date_finished)).first()757 Desc(Job.date_finished)).first()
757 return latest_job758 return latest_job
758759