Merge lp:~stevenk/launchpad/productseries-preload-for-merges into lp:launchpad

Proposed by Steve Kowalik
Status: Merged
Approved by: William Grant
Approved revision: no longer in the source branch.
Merged at revision: 16533
Proposed branch: lp:~stevenk/launchpad/productseries-preload-for-merges
Merge into: lp:launchpad
Diff against target: 169 lines (+31/-34)
3 files modified
lib/lp/code/browser/tests/test_branchmergeproposallisting.py (+10/-1)
lib/lp/code/model/branch.py (+1/-3)
lib/lp/code/model/branchcollection.py (+20/-30)
To merge this branch: bzr merge lp:~stevenk/launchpad/productseries-preload-for-merges
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+153052@code.launchpad.net

Commit message

Rewrite the propertycache loops for BMP preloading.

Description of the change

Rewrite the propertycache loops for BMP preloading -- I'm not certain why setting them to [] was guarded, and then each would end up treating the cache's properties like lists anyway.

I've cleaned up branchcollection more to claw this branch back to net-negative.

To post a comment you must log in.
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/browser/tests/test_branchmergeproposallisting.py'
2--- lib/lp/code/browser/tests/test_branchmergeproposallisting.py 2013-03-04 04:17:17 +0000
3+++ lib/lp/code/browser/tests/test_branchmergeproposallisting.py 2013-03-15 01:30:30 +0000
4@@ -208,7 +208,16 @@
5 self.getViewBrowser(
6 product, '+merges', rootsite='code', user=product.owner)
7 self.assertThat(recorder, HasQueryCount(Equals(40)))
8-
9+
10+ def test_productseries(self):
11+ target = self.factory.makeBranch()
12+ unique_name = target.unique_name
13+ with person_logged_in(target.product.owner):
14+ target.product.development_focus.branch = target
15+ self.factory.makeBranchMergeProposal(target_branch=target)
16+ view = self.getViewBrowser(target, '+merges', rootsite='code')
17+ self.assertIn(unique_name, view.contents)
18+
19
20 class ActiveReviewGroupsTest(TestCaseWithFactory):
21 """Tests for groupings used in for active reviews."""
22
23=== modified file 'lib/lp/code/model/branch.py'
24--- lib/lp/code/model/branch.py 2013-02-21 06:29:24 +0000
25+++ lib/lp/code/model/branch.py 2013-03-15 01:30:30 +0000
26@@ -853,9 +853,7 @@
27 # This is eager loaded by BranchCollection.getBranches.
28 # Imported here to avoid circular import.
29 from lp.registry.model.productseries import ProductSeries
30- return Store.of(self).find(
31- ProductSeries,
32- ProductSeries.branch == self)
33+ return Store.of(self).find(ProductSeries, ProductSeries.branch == self)
34
35 def associatedProductSeries(self):
36 """See `IBranch`."""
37
38=== modified file 'lib/lp/code/model/branchcollection.py'
39--- lib/lp/code/model/branchcollection.py 2013-02-14 03:53:10 +0000
40+++ lib/lp/code/model/branchcollection.py 2013-03-15 01:30:30 +0000
41@@ -12,7 +12,6 @@
42 from functools import partial
43 from operator import attrgetter
44
45-from lazr.restful.utils import safe_hasattr
46 from lazr.uri import (
47 InvalidURIError,
48 URI,
49@@ -255,12 +254,9 @@
50 for branch in branches)
51 branch_ids = caches.keys()
52 for cache in caches.values():
53- if not safe_hasattr(cache, '_associatedProductSeries'):
54- cache._associatedProductSeries = []
55- if not safe_hasattr(cache, '_associatedSuiteSourcePackages'):
56- cache._associatedSuiteSourcePackages = []
57- if not safe_hasattr(cache, 'code_import'):
58- cache.code_import = None
59+ cache._associatedProductSeries = []
60+ cache._associatedSuiteSourcePackages = []
61+ cache.code_import = None
62 # associatedProductSeries
63 # Imported here to avoid circular import.
64 from lp.registry.model.productseries import ProductSeries
65@@ -306,8 +302,8 @@
66
67 def cache_permission(branch):
68 if self._user:
69- get_property_cache(branch)._known_viewers = (
70- set([self._user.id]))
71+ get_property_cache(branch)._known_viewers = set(
72+ [self._user.id])
73 return branch
74
75 eager_load_hook = (
76@@ -528,8 +524,7 @@
77 linked_bugtasks[branch.id].extend(
78 filter_bugtasks_by_context(branch.target.context, tasks))
79
80- return [make_rev_info(
81- rev, merge_proposal_revs, linked_bugtasks)
82+ return [make_rev_info(rev, merge_proposal_revs, linked_bugtasks)
83 for rev in revisions]
84
85 def getTeamsWithBranches(self, person):
86@@ -543,8 +538,7 @@
87 Person,
88 Person.id == TeamParticipation.teamID,
89 TeamParticipation.person == person,
90- TeamParticipation.team != person,
91- Person.id.is_in(branch_query))
92+ TeamParticipation.team != person, Person.id.is_in(branch_query))
93
94 def inProduct(self, product):
95 """See `IBranchCollection`."""
96@@ -555,8 +549,7 @@
97 """See `IBranchCollection`."""
98 return self._filterBy(
99 [Product.project == project.id],
100- table=Product,
101- join=Join(Product, Branch.product == Product.id))
102+ table=Product, join=Join(Product, Branch.product == Product.id))
103
104 def inDistribution(self, distribution):
105 """See `IBranchCollection`."""
106@@ -599,14 +592,13 @@
107
108 def isJunk(self):
109 """See `IBranchCollection`."""
110- return self._filterBy([
111- Branch.product == None,
112- Branch.sourcepackagename == None])
113+ return self._filterBy(
114+ [Branch.product == None, Branch.sourcepackagename == None])
115
116 def isPrivate(self):
117 """See `IBranchCollection`."""
118- return self._filterBy([
119- Branch.information_type.is_in(PRIVATE_INFORMATION_TYPES)])
120+ return self._filterBy(
121+ [Branch.information_type.is_in(PRIVATE_INFORMATION_TYPES)])
122
123 def isExclusive(self):
124 """See `IBranchCollection`."""
125@@ -617,7 +609,7 @@
126
127 def isSeries(self):
128 """See `IBranchCollection`."""
129- # ProductSeries import's this module.
130+ # Circular imports.
131 from lp.registry.model.productseries import ProductSeries
132 return self._filterBy(
133 [Branch.id == ProductSeries.branchID],
134@@ -633,9 +625,7 @@
135 subquery = Select(
136 TeamParticipation.teamID,
137 where=TeamParticipation.personID == person.id)
138- filter = [In(Branch.ownerID, subquery)]
139-
140- return self._filterBy(filter, symmetric=False)
141+ return self._filterBy([In(Branch.ownerID, subquery)], symmetric=False)
142
143 def registeredBy(self, person):
144 """See `IBranchCollection`."""
145@@ -721,18 +711,18 @@
146 self._asymmetric_filter_expressions, self._asymmetric_tables)
147
148 def withBranchType(self, *branch_types):
149- return self._filterBy([Branch.branch_type.is_in(branch_types)],
150- symmetric=False)
151+ return self._filterBy(
152+ [Branch.branch_type.is_in(branch_types)], symmetric=False)
153
154 def withLifecycleStatus(self, *statuses):
155 """See `IBranchCollection`."""
156- return self._filterBy([Branch.lifecycle_status.is_in(statuses)],
157- symmetric=False)
158+ return self._filterBy(
159+ [Branch.lifecycle_status.is_in(statuses)], symmetric=False)
160
161 def modifiedSince(self, epoch):
162 """See `IBranchCollection`."""
163- return self._filterBy([Branch.date_last_modified > epoch],
164- symmetric=False)
165+ return self._filterBy(
166+ [Branch.date_last_modified > epoch], symmetric=False)
167
168 def scannedSince(self, epoch):
169 """See `IBranchCollection`."""