Merge lp:~lifeless/launchpad/bug-615647 into lp:launchpad

Proposed by Robert Collins
Status: Merged
Approved by: Robert Collins
Approved revision: no longer in the source branch.
Merged at revision: 12631
Proposed branch: lp:~lifeless/launchpad/bug-615647
Merge into: lp:launchpad
Diff against target: 57 lines (+15/-14)
2 files modified
lib/lp/code/interfaces/branchmergeproposal.py (+1/-1)
lib/lp/code/model/branchmergeproposal.py (+14/-13)
To merge this branch: bzr merge lp:~lifeless/launchpad/bug-615647
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
Ian Booth (community) *code Approve
Review via email: mp+54150@code.launchpad.net

Commit message

Make determining unmerged revisions a whole lot cheaper.

Description of the change

Use SQL that limits the revisions of source considered - rather than a full set difference, we know that we have a DAG so we can use the information - if X isn't visible, neither is anything with a lower sequence.

To post a comment you must log in.
Revision history for this message
Ian Booth (wallyworld) wrote :

Looks ok to me.

review: Approve (*code)
Revision history for this message
Robert Collins (lifeless) wrote :

FTW

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/interfaces/branchmergeproposal.py'
2--- lib/lp/code/interfaces/branchmergeproposal.py 2011-03-04 01:16:03 +0000
3+++ lib/lp/code/interfaces/branchmergeproposal.py 2011-03-21 04:43:40 +0000
4@@ -469,7 +469,7 @@
5 def getUnlandedSourceBranchRevisions():
6 """Return a sequence of `BranchRevision` objects.
7
8- Returns those revisions that are in the revision history for the
9+ Returns up to 10 revisions that are in the revision history for the
10 source branch that are not in the revision history of the target
11 branch. These are the revisions that have been committed to the
12 source branch since it branched off the target branch.
13
14=== modified file 'lib/lp/code/model/branchmergeproposal.py'
15--- lib/lp/code/model/branchmergeproposal.py 2011-03-03 13:12:37 +0000
16+++ lib/lp/code/model/branchmergeproposal.py 2011-03-21 04:43:40 +0000
17@@ -27,6 +27,7 @@
18 LeftJoin,
19 Or,
20 Select,
21+ SQL,
22 )
23 from storm.info import ClassAlias
24 from storm.locals import (
25@@ -647,19 +648,19 @@
26 def getUnlandedSourceBranchRevisions(self):
27 """See `IBranchMergeProposal`."""
28 store = Store.of(self)
29- SourceRevision = ClassAlias(BranchRevision)
30- TargetRevision = ClassAlias(BranchRevision)
31- target_join = LeftJoin(
32- TargetRevision, And(
33- TargetRevision.branch_id == self.target_branch.id,
34- TargetRevision.revision_id == SourceRevision.revision_id))
35- origin = [SourceRevision, target_join]
36- result = store.using(*origin).find(
37- SourceRevision,
38- SourceRevision.branch_id == self.source_branch.id,
39- SourceRevision.sequence != None,
40- TargetRevision.branch_id == None)
41- return result.order_by(Desc(SourceRevision.sequence)).config(limit=10)
42+ source = SQL("""source AS (SELECT BranchRevision.branch,
43+ BranchRevision.revision, Branchrevision.sequence FROM
44+ BranchRevision WHERE BranchRevision.branch = %s and
45+ BranchRevision.sequence IS NOT NULL ORDER BY BranchRevision.branch
46+ DESC, BranchRevision.sequence DESC
47+ LIMIT 10)""" % self.source_branch.id)
48+ where = SQL("""BranchRevision.revision NOT IN (SELECT revision from
49+ BranchRevision AS target where target.branch = %s and
50+ BranchRevision.revision = target.revision)""" % self.target_branch.id)
51+ using = SQL("""source as BranchRevision""")
52+ revisions = store.with_(source).using(using).find(BranchRevision, where)
53+ return list(revisions.order_by(
54+ Desc(BranchRevision.sequence)).config(limit=10))
55
56 def createComment(self, owner, subject, content=None, vote=None,
57 review_type=None, parent=None, _date_created=DEFAULT,