Merge lp:~lifeless/launchpad/registry-packagings into lp:launchpad

Proposed by Robert Collins
Status: Merged
Approved by: Curtis Hovey
Approved revision: no longer in the source branch.
Merged at revision: 11317
Proposed branch: lp:~lifeless/launchpad/registry-packagings
Merge into: lp:launchpad
Diff against target: 86 lines (+23/-9)
3 files modified
lib/lp/registry/browser/distroseries.py (+1/-1)
lib/lp/registry/doc/distroseries.txt (+1/-1)
lib/lp/registry/model/distroseries.py (+21/-7)
To merge this branch: bzr merge lp:~lifeless/launchpad/registry-packagings
Reviewer Review Type Date Requested Status
Robert Collins (community) release-critical Approve
Curtis Hovey (community) Approve
Julian Edwards release-manager Pending
Review via email: mp+32164@code.launchpad.net

Commit message

Change listified packagings into DecoratedResultSets to allow count() without deserialising thousands of objects.

Description of the change

Help address a high frequency timeout, bug 612358.

This probably is RC, as IIRC its an edge specific issue at the moment.

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

Thanks for working this issue out with me. This looks good to land.

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

Using my own rc stamp after discussion with Curtis.

review: Approve (release-critical)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/browser/distroseries.py'
2--- lib/lp/registry/browser/distroseries.py 2010-08-06 12:49:27 +0000
3+++ lib/lp/registry/browser/distroseries.py 2010-08-10 03:04:59 +0000
4@@ -317,7 +317,7 @@
5 @cachedproperty
6 def num_linked_packages(self):
7 """The number of linked packagings for this distroseries."""
8- return len(self.context.packagings)
9+ return self.context.packagings.count()
10
11 @property
12 def num_unlinked_packages(self):
13
14=== modified file 'lib/lp/registry/doc/distroseries.txt'
15--- lib/lp/registry/doc/distroseries.txt 2010-07-28 02:02:25 +0000
16+++ lib/lp/registry/doc/distroseries.txt 2010-08-10 03:04:59 +0000
17@@ -479,7 +479,7 @@
18 >>> distribution = factory.makeDistribution()
19 >>> distroseries = factory.makeDistroRelease(distribution=distribution)
20 >>> pkgs = distroseries.getMostRecentlyLinkedPackagings()
21- >>> print len(pkgs)
22+ >>> print pkgs.count()
23 0
24
25 >>> for name in ['aaron', 'bjorn', 'chex', 'deryck', 'edwin', 'francis']:
26
27=== modified file 'lib/lp/registry/model/distroseries.py'
28--- lib/lp/registry/model/distroseries.py 2010-08-02 02:13:52 +0000
29+++ lib/lp/registry/model/distroseries.py 2010-08-10 03:04:59 +0000
30@@ -286,10 +286,20 @@
31
32 @cachedproperty
33 def _all_packagings(self):
34- """Get an unordered list of all packagings."""
35+ """Get an unordered list of all packagings.
36+
37+ :return: A ResultSet which can be decorated or tuned further. Use
38+ DistroSeries._packaging_row_to_packaging to extract the
39+ packaging objects out.
40+ """
41 # We join to SourcePackageName, ProductSeries, and Product to cache
42 # the objects that are implicitly needed to work with a
43 # Packaging object.
44+ # NB: precaching objects like this method tries to do has a very poor
45+ # hit rate with storm - many queries will still be executed; consider
46+ # ripping this out and instead allowing explicit inclusion of things
47+ # like Person._all_members does - returning a cached object graph.
48+ # -- RBC 20100810
49 # Avoid circular import failures.
50 from lp.registry.model.product import Product
51 from lp.registry.model.productseries import ProductSeries
52@@ -309,14 +319,19 @@
53 results = IStore(self).using(*origin).find(find_spec, condition)
54 return results
55
56+ @staticmethod
57+ def _packaging_row_to_packaging(row):
58+ # each row has:
59+ # (packaging, spn, product_series, product)
60+ return row[0]
61+
62 @property
63 def packagings(self):
64 """See `IDistroSeries`."""
65 results = self._all_packagings
66 results = results.order_by(SourcePackageName.name)
67- return [
68- packaging
69- for (packaging, spn, product_series, product) in results]
70+ return DecoratedResultSet(results,
71+ DistroSeries._packaging_row_to_packaging)
72
73 def getPrioritizedUnlinkedSourcePackages(self):
74 """See `IDistroSeries`.
75@@ -454,9 +469,8 @@
76 # identical creation dates.
77 results = results.order_by(Desc(Packaging.datecreated),
78 SourcePackageName.name)[:5]
79- return [
80- packaging
81- for (packaging, spn, product_series, product) in results]
82+ return DecoratedResultSet(results,
83+ DistroSeries._packaging_row_to_packaging)
84
85 @property
86 def supported(self):