Merge lp:~rvb/launchpad/revert-14355 into lp:launchpad

Proposed by Raphaël Badin
Status: Merged
Merged at revision: 14374
Proposed branch: lp:~rvb/launchpad/revert-14355
Merge into: lp:launchpad
Diff against target: 188 lines (+22/-77)
1 file modified
lib/lp/code/model/branchcollection.py (+22/-77)
To merge this branch: bzr merge lp:~rvb/launchpad/revert-14355
Reviewer Review Type Date Requested Status
Raphaël Badin (community) Approve
Review via email: mp+83183@code.launchpad.net

Commit message

Revert r14355.

Description of the change

This branch reverts r14355. The refactored query (which uses 2 CTEs, see OOPS-8c4f00a21be3b28698de236433c26fd3) as a worse performance than the original one. Reverted MP: https://code.launchpad.net/~rvb/launchpad/activereviews-bug-867941-hugequery/+merge/82650.

To post a comment you must log in.
Revision history for this message
Raphaël Badin (rvb) wrote :

This is a straight revert so I'm self reviewing.

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/branchcollection.py'
2--- lib/lp/code/model/branchcollection.py 2011-11-22 10:18:22 +0000
3+++ lib/lp/code/model/branchcollection.py 2011-11-23 16:10:42 +0000
4@@ -128,16 +128,6 @@
5 if exclude_from_search is None:
6 exclude_from_search = []
7 self._exclude_from_search = exclude_from_search
8- self._with_dict = {}
9-
10- @property
11- def store_with_with(self):
12- store = self.store
13- if len(self._with_dict) != 0:
14- with_expr = [With(name, expr)
15- for (name, expr) in self._with_dict.items()]
16- store = store.with_(with_expr)
17- return store
18
19 def count(self):
20 """See `IBranchCollection`."""
21@@ -275,8 +265,7 @@
22 self._tables.values() + self._asymmetric_tables.values())
23 tables = [Branch] + list(all_tables)
24 expressions = self._getBranchExpressions()
25- resultset = self.store_with_with.using(
26- *tables).find(Branch, *expressions)
27+ resultset = self.store.using(*tables).find(Branch, *expressions)
28 if not eager_load:
29 return resultset
30
31@@ -297,15 +286,6 @@
32 target_branch=None, merged_revnos=None,
33 eager_load=False):
34 """See `IBranchCollection`."""
35- return self._getMergeProposals(
36- statuses=statuses, for_branches=for_branches,
37- target_branch=target_branch, merged_revnos=merged_revnos,
38- eager_load=eager_load)
39-
40- def _getMergeProposals(self, statuses=None, for_branches=None,
41- target_branch=None, merged_revnos=None,
42- eager_load=False, return_ids=False,
43- include_with=True):
44 if for_branches is not None and not for_branches:
45 # We have an empty branches list, so we can shortcut.
46 return EmptyResultSet()
47@@ -317,19 +297,15 @@
48 target_branch is not None or
49 merged_revnos is not None):
50 return self._naiveGetMergeProposals(statuses, for_branches,
51- target_branch, merged_revnos, eager_load,
52- return_ids=return_ids, include_with=include_with)
53+ target_branch, merged_revnos, eager_load)
54 else:
55 # When examining merge proposals in a scope, this is a moderately
56 # effective set of constrained queries. It is not effective when
57 # unscoped or when tight constraints on branches are present.
58- return self._scopedGetMergeProposals(
59- statuses, return_ids=return_ids)
60+ return self._scopedGetMergeProposals(statuses)
61
62 def _naiveGetMergeProposals(self, statuses=None, for_branches=None,
63- target_branch=None, merged_revnos=None,
64- eager_load=False, return_ids=False,
65- include_with=True):
66+ target_branch=None, merged_revnos=None, eager_load=False):
67
68 def do_eager_load(rows):
69 branch_ids = set()
70@@ -386,20 +362,14 @@
71 if statuses is not None:
72 expressions.append(
73 BranchMergeProposal.queue_status.is_in(statuses))
74- if include_with:
75- store = self.store_with_with
76- else:
77- store = self.store
78- returned_obj = (
79- BranchMergeProposal.id if return_ids else BranchMergeProposal)
80- resultset = store.using(*tables).find(
81- returned_obj, *expressions)
82+ resultset = self.store.using(*tables).find(
83+ BranchMergeProposal, *expressions)
84 if not eager_load:
85 return resultset
86 else:
87 return DecoratedResultSet(resultset, pre_iter_hook=do_eager_load)
88
89- def _scopedGetMergeProposals(self, statuses, return_ids=False):
90+ def _scopedGetMergeProposals(self, statuses):
91 scope_tables = [Branch] + self._tables.values()
92 scope_expressions = self._branch_filter_expressions
93 select = self.store.using(*scope_tables).find(
94@@ -422,23 +392,16 @@
95 if statuses is not None:
96 expressions.append(
97 BranchMergeProposal.queue_status.is_in(statuses))
98- returned_obj = (
99- BranchMergeProposal.id if return_ids else BranchMergeProposal)
100 return self.store.with_(with_expr).using(*tables).find(
101- returned_obj, *expressions)
102+ BranchMergeProposal, *expressions)
103
104 def getMergeProposalsForPerson(self, person, status=None):
105 """See `IBranchCollection`."""
106 # We want to limit the proposals to those where the source branch is
107 # limited by the defined collection.
108- owned = self.ownedBy(person)._getMergeProposals(
109- status, include_with=False, return_ids=True)
110- reviewing = self._getMergeProposalsForReviewer(
111- person, status, include_with=False, return_ids=True)
112- result = owned.union(reviewing)
113- resultset = self.store_with_with.using([BranchMergeProposal]).find(
114- BranchMergeProposal,
115- In(BranchMergeProposal.id, result._get_select()))
116+ owned = self.ownedBy(person).getMergeProposals(status)
117+ reviewing = self.getMergeProposalsForReviewer(person, status)
118+ resultset = owned.union(reviewing)
119
120 def do_eager_load(rows):
121 # Load the related diffs.
122@@ -468,10 +431,6 @@
123
124 def getMergeProposalsForReviewer(self, reviewer, status=None):
125 """See `IBranchCollection`."""
126- return self._getMergeProposalsForReviewer(reviewer, status=status)
127-
128- def _getMergeProposalsForReviewer(self, reviewer, status=None,
129- include_with=True, return_ids=False):
130 tables = [
131 BranchMergeProposal,
132 Join(CodeReviewVoteReference,
133@@ -491,14 +450,8 @@
134 if status is not None:
135 expressions.append(
136 BranchMergeProposal.queue_status.is_in(status))
137- if include_with:
138- store = self.store_with_with
139- else:
140- store = self.store
141- returned_obj = (
142- BranchMergeProposal.id if return_ids else BranchMergeProposal)
143- proposals = store.using(*tables).find(
144- returned_obj, *expressions)
145+ proposals = self.store.using(*tables).find(
146+ BranchMergeProposal, *expressions)
147 # Apply sorting here as we can't do it in the browser code. We need
148 # to think carefully about the best places to do this, but not here
149 # nor now.
150@@ -900,29 +853,21 @@
151 Branch.transitively_private == True)))
152 return private_branches
153
154- def _addVisibleBranchesCTE(self):
155- """Add the 'visible_branches' CTE to self._with_dict.
156-
157- """
158- public_branches = Branch.transitively_private == False
159- if self._private_branch_ids is not None:
160- branches = Or(
161- public_branches,
162- Branch.id.is_in(self._private_branch_ids))
163- else:
164- branches = public_branches
165- branches_select = self.store.using(
166- [Branch]).find(Branch.id, branches)._get_select()
167- self._with_dict.update({'visible_branches': branches_select})
168-
169 def _getBranchVisibilityExpression(self, branch_class=Branch):
170 """Return the where clauses for visibility.
171
172 :param branch_class: The Branch class to use - permits using
173 ClassAliases.
174 """
175- self._addVisibleBranchesCTE()
176- return [branch_class.id.is_in(SQL("SELECT id FROM visible_branches"))]
177+ public_branches = branch_class.transitively_private == False
178+ if self._private_branch_ids is None:
179+ # Public only.
180+ return [public_branches]
181+ else:
182+ public_or_private = Or(
183+ public_branches,
184+ branch_class.id.is_in(self._private_branch_ids))
185+ return [public_or_private]
186
187 def _getCandidateBranchesWith(self):
188 """Return WITH clauses defining candidate branches.