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.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/code/browser/tests/test_branchmergeproposallisting.py'
--- lib/lp/code/browser/tests/test_branchmergeproposallisting.py 2013-03-04 04:17:17 +0000
+++ lib/lp/code/browser/tests/test_branchmergeproposallisting.py 2013-03-15 01:30:30 +0000
@@ -208,7 +208,16 @@
208 self.getViewBrowser(208 self.getViewBrowser(
209 product, '+merges', rootsite='code', user=product.owner)209 product, '+merges', rootsite='code', user=product.owner)
210 self.assertThat(recorder, HasQueryCount(Equals(40)))210 self.assertThat(recorder, HasQueryCount(Equals(40)))
211 211
212 def test_productseries(self):
213 target = self.factory.makeBranch()
214 unique_name = target.unique_name
215 with person_logged_in(target.product.owner):
216 target.product.development_focus.branch = target
217 self.factory.makeBranchMergeProposal(target_branch=target)
218 view = self.getViewBrowser(target, '+merges', rootsite='code')
219 self.assertIn(unique_name, view.contents)
220
212221
213class ActiveReviewGroupsTest(TestCaseWithFactory):222class ActiveReviewGroupsTest(TestCaseWithFactory):
214 """Tests for groupings used in for active reviews."""223 """Tests for groupings used in for active reviews."""
215224
=== modified file 'lib/lp/code/model/branch.py'
--- lib/lp/code/model/branch.py 2013-02-21 06:29:24 +0000
+++ lib/lp/code/model/branch.py 2013-03-15 01:30:30 +0000
@@ -853,9 +853,7 @@
853 # This is eager loaded by BranchCollection.getBranches.853 # This is eager loaded by BranchCollection.getBranches.
854 # Imported here to avoid circular import.854 # Imported here to avoid circular import.
855 from lp.registry.model.productseries import ProductSeries855 from lp.registry.model.productseries import ProductSeries
856 return Store.of(self).find(856 return Store.of(self).find(ProductSeries, ProductSeries.branch == self)
857 ProductSeries,
858 ProductSeries.branch == self)
859857
860 def associatedProductSeries(self):858 def associatedProductSeries(self):
861 """See `IBranch`."""859 """See `IBranch`."""
862860
=== modified file 'lib/lp/code/model/branchcollection.py'
--- lib/lp/code/model/branchcollection.py 2013-02-14 03:53:10 +0000
+++ lib/lp/code/model/branchcollection.py 2013-03-15 01:30:30 +0000
@@ -12,7 +12,6 @@
12from functools import partial12from functools import partial
13from operator import attrgetter13from operator import attrgetter
1414
15from lazr.restful.utils import safe_hasattr
16from lazr.uri import (15from lazr.uri import (
17 InvalidURIError,16 InvalidURIError,
18 URI,17 URI,
@@ -255,12 +254,9 @@
255 for branch in branches)254 for branch in branches)
256 branch_ids = caches.keys()255 branch_ids = caches.keys()
257 for cache in caches.values():256 for cache in caches.values():
258 if not safe_hasattr(cache, '_associatedProductSeries'):257 cache._associatedProductSeries = []
259 cache._associatedProductSeries = []258 cache._associatedSuiteSourcePackages = []
260 if not safe_hasattr(cache, '_associatedSuiteSourcePackages'):259 cache.code_import = None
261 cache._associatedSuiteSourcePackages = []
262 if not safe_hasattr(cache, 'code_import'):
263 cache.code_import = None
264 # associatedProductSeries260 # associatedProductSeries
265 # Imported here to avoid circular import.261 # Imported here to avoid circular import.
266 from lp.registry.model.productseries import ProductSeries262 from lp.registry.model.productseries import ProductSeries
@@ -306,8 +302,8 @@
306302
307 def cache_permission(branch):303 def cache_permission(branch):
308 if self._user:304 if self._user:
309 get_property_cache(branch)._known_viewers = (305 get_property_cache(branch)._known_viewers = set(
310 set([self._user.id]))306 [self._user.id])
311 return branch307 return branch
312308
313 eager_load_hook = (309 eager_load_hook = (
@@ -528,8 +524,7 @@
528 linked_bugtasks[branch.id].extend(524 linked_bugtasks[branch.id].extend(
529 filter_bugtasks_by_context(branch.target.context, tasks))525 filter_bugtasks_by_context(branch.target.context, tasks))
530526
531 return [make_rev_info(527 return [make_rev_info(rev, merge_proposal_revs, linked_bugtasks)
532 rev, merge_proposal_revs, linked_bugtasks)
533 for rev in revisions]528 for rev in revisions]
534529
535 def getTeamsWithBranches(self, person):530 def getTeamsWithBranches(self, person):
@@ -543,8 +538,7 @@
543 Person,538 Person,
544 Person.id == TeamParticipation.teamID,539 Person.id == TeamParticipation.teamID,
545 TeamParticipation.person == person,540 TeamParticipation.person == person,
546 TeamParticipation.team != person,541 TeamParticipation.team != person, Person.id.is_in(branch_query))
547 Person.id.is_in(branch_query))
548542
549 def inProduct(self, product):543 def inProduct(self, product):
550 """See `IBranchCollection`."""544 """See `IBranchCollection`."""
@@ -555,8 +549,7 @@
555 """See `IBranchCollection`."""549 """See `IBranchCollection`."""
556 return self._filterBy(550 return self._filterBy(
557 [Product.project == project.id],551 [Product.project == project.id],
558 table=Product,552 table=Product, join=Join(Product, Branch.product == Product.id))
559 join=Join(Product, Branch.product == Product.id))
560553
561 def inDistribution(self, distribution):554 def inDistribution(self, distribution):
562 """See `IBranchCollection`."""555 """See `IBranchCollection`."""
@@ -599,14 +592,13 @@
599592
600 def isJunk(self):593 def isJunk(self):
601 """See `IBranchCollection`."""594 """See `IBranchCollection`."""
602 return self._filterBy([595 return self._filterBy(
603 Branch.product == None,596 [Branch.product == None, Branch.sourcepackagename == None])
604 Branch.sourcepackagename == None])
605597
606 def isPrivate(self):598 def isPrivate(self):
607 """See `IBranchCollection`."""599 """See `IBranchCollection`."""
608 return self._filterBy([600 return self._filterBy(
609 Branch.information_type.is_in(PRIVATE_INFORMATION_TYPES)])601 [Branch.information_type.is_in(PRIVATE_INFORMATION_TYPES)])
610602
611 def isExclusive(self):603 def isExclusive(self):
612 """See `IBranchCollection`."""604 """See `IBranchCollection`."""
@@ -617,7 +609,7 @@
617609
618 def isSeries(self):610 def isSeries(self):
619 """See `IBranchCollection`."""611 """See `IBranchCollection`."""
620 # ProductSeries import's this module.612 # Circular imports.
621 from lp.registry.model.productseries import ProductSeries613 from lp.registry.model.productseries import ProductSeries
622 return self._filterBy(614 return self._filterBy(
623 [Branch.id == ProductSeries.branchID],615 [Branch.id == ProductSeries.branchID],
@@ -633,9 +625,7 @@
633 subquery = Select(625 subquery = Select(
634 TeamParticipation.teamID,626 TeamParticipation.teamID,
635 where=TeamParticipation.personID == person.id)627 where=TeamParticipation.personID == person.id)
636 filter = [In(Branch.ownerID, subquery)]628 return self._filterBy([In(Branch.ownerID, subquery)], symmetric=False)
637
638 return self._filterBy(filter, symmetric=False)
639629
640 def registeredBy(self, person):630 def registeredBy(self, person):
641 """See `IBranchCollection`."""631 """See `IBranchCollection`."""
@@ -721,18 +711,18 @@
721 self._asymmetric_filter_expressions, self._asymmetric_tables)711 self._asymmetric_filter_expressions, self._asymmetric_tables)
722712
723 def withBranchType(self, *branch_types):713 def withBranchType(self, *branch_types):
724 return self._filterBy([Branch.branch_type.is_in(branch_types)],714 return self._filterBy(
725 symmetric=False)715 [Branch.branch_type.is_in(branch_types)], symmetric=False)
726716
727 def withLifecycleStatus(self, *statuses):717 def withLifecycleStatus(self, *statuses):
728 """See `IBranchCollection`."""718 """See `IBranchCollection`."""
729 return self._filterBy([Branch.lifecycle_status.is_in(statuses)],719 return self._filterBy(
730 symmetric=False)720 [Branch.lifecycle_status.is_in(statuses)], symmetric=False)
731721
732 def modifiedSince(self, epoch):722 def modifiedSince(self, epoch):
733 """See `IBranchCollection`."""723 """See `IBranchCollection`."""
734 return self._filterBy([Branch.date_last_modified > epoch],724 return self._filterBy(
735 symmetric=False)725 [Branch.date_last_modified > epoch], symmetric=False)
736726
737 def scannedSince(self, epoch):727 def scannedSince(self, epoch):
738 """See `IBranchCollection`."""728 """See `IBranchCollection`."""