Merge lp:~lifeless/launchpad/soyuz into lp:launchpad

Proposed by Robert Collins
Status: Merged
Approved by: Robert Collins
Approved revision: no longer in the source branch.
Merged at revision: 11856
Proposed branch: lp:~lifeless/launchpad/soyuz
Merge into: lp:launchpad
Diff against target: 157 lines (+57/-12)
4 files modified
lib/lp/registry/model/distroseries.py (+32/-1)
lib/lp/soyuz/adapters/archivesourcepublication.py (+2/-0)
lib/lp/soyuz/doc/publishing.txt (+16/-1)
lib/lp/soyuz/model/publishing.py (+7/-10)
To merge this branch: bzr merge lp:~lifeless/launchpad/soyuz
Reviewer Review Type Date Requested Status
Tim Penhey (community) mentore Approve
Steve Kowalik (community) code* Approve
Review via email: mp+39934@code.launchpad.net

Commit message

Incremental improvement for +packages pages.

Description of the change

Incremental improvement for the +packages pages, eager loading the attribute triggering most DB queries and tuning the logic to do only one related call. We may still have DB access being triggered, but this should help.

To post a comment you must log in.
Revision history for this message
Steve Kowalik (stevenk) wrote :

My only concern with this is what impact the caching will have on the publisher, but the code itself looks good.

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

The publisher doesn't seem to use that attribute AFAICT. IMBW, tests will show.

Revision history for this message
Tim Penhey (thumper) wrote :

Since we want to make soyuz code more understandable, can you please just add to the docstring at the top of the setNewerDistroSeriesVersions as to what spphs (or spph objects) are?

It wasn't until much further down that change that I actually had any inkling as to what it was.

review: Approve (mentore)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/model/distroseries.py'
2--- lib/lp/registry/model/distroseries.py 2010-11-02 06:21:58 +0000
3+++ lib/lp/registry/model/distroseries.py 2010-11-03 17:51:56 +0000
4@@ -12,9 +12,11 @@
5 'DistroSeriesSet',
6 ]
7
8+import collections
9 from cStringIO import StringIO
10 import logging
11
12+import apt_pkg
13 from sqlobject import (
14 BoolCol,
15 ForeignKey,
16@@ -119,7 +121,10 @@
17 from lp.registry.model.structuralsubscription import (
18 StructuralSubscriptionTargetMixin,
19 )
20-from lp.services.propertycache import cachedproperty
21+from lp.services.propertycache import (
22+ cachedproperty,
23+ get_property_cache,
24+ )
25 from lp.services.worlddata.model.language import Language
26 from lp.soyuz.enums import (
27 ArchivePurpose,
28@@ -1506,6 +1511,32 @@
29
30 return distro_sprs
31
32+ @staticmethod
33+ def setNewerDistroSeriesVersions(spphs):
34+ """Set the newer_distroseries_version attribute on the spph entries.
35+
36+ :param spphs: The SourcePackagePublishingHistory objects to set the
37+ newer_distroseries_version attribute on.
38+ """
39+ # Partition by distro series to use getCurrentSourceReleases
40+ distro_series = collections.defaultdict(list)
41+ for spph in spphs:
42+ distro_series[spph.distroseries].append(spph)
43+ for series, spphs in distro_series.items():
44+ packagenames = set()
45+ for spph in spphs:
46+ packagenames.add(spph.sourcepackagerelease.sourcepackagename)
47+ latest_releases = series.getCurrentSourceReleases(
48+ packagenames)
49+ for spph in spphs:
50+ latest_release = latest_releases.get(spph.meta_sourcepackage, None)
51+ if latest_release is not None and apt_pkg.VersionCompare(
52+ latest_release.version, spph.source_package_version) > 0:
53+ version = latest_release
54+ else:
55+ version = None
56+ get_property_cache(spph).newer_distroseries_version = version
57+
58 def createQueueEntry(self, pocket, changesfilename, changesfilecontent,
59 archive, signing_key=None):
60 """See `IDistroSeries`."""
61
62=== modified file 'lib/lp/soyuz/adapters/archivesourcepublication.py'
63--- lib/lp/soyuz/adapters/archivesourcepublication.py 2010-08-20 20:31:18 +0000
64+++ lib/lp/soyuz/adapters/archivesourcepublication.py 2010-11-03 17:51:56 +0000
65@@ -19,6 +19,7 @@
66 from zope.component import getUtility
67
68 from canonical.launchpad.browser.librarian import ProxiedLibraryFileAlias
69+from lp.registry.model.distroseries import DistroSeries
70 from lp.soyuz.interfaces.publishing import (
71 IPublishingSet,
72 ISourcePackagePublishingHistory,
73@@ -163,6 +164,7 @@
74 builds_by_source = self.getBuildsBySource()
75 unpublished_builds_by_source = self.getUnpublishedBuildsBySource()
76 changesfiles_by_source = self.getChangesFileBySource()
77+ DistroSeries.setNewerDistroSeriesVersions(self._source_publications)
78
79 # Build the decorated object with the information we have.
80 for pub in self._source_publications:
81
82=== modified file 'lib/lp/soyuz/doc/publishing.txt'
83--- lib/lp/soyuz/doc/publishing.txt 2010-10-19 18:44:31 +0000
84+++ lib/lp/soyuz/doc/publishing.txt 2010-11-03 17:51:56 +0000
85@@ -135,9 +135,18 @@
86 ... distroseries=pub.distroseries, version="1.1",
87 ... sourcename='iceweasel')
88
89+ >>> from lp.services.propertycache import get_property_cache
90+ >>> del get_property_cache(pub).newer_distroseries_version
91 >>> print pub.newer_distroseries_version.title
92 "iceweasel" 1.1 source package in The Warty Warthog Release
93
94+We can calculate the newer_distroseries_version for many spph objects at once.
95+
96+ >>> del get_property_cache(pub).newer_distroseries_version
97+ >>> pub.distroseries.setNewerDistroSeriesVersions([pub])
98+ >>> print get_property_cache(pub).newer_distroseries_version.title
99+ "iceweasel" 1.1 source package in The Warty Warthog Release
100+
101 A helper is also included to create a summary of the build statuses for
102 the spph's related builds, getStatusSummaryForBuilds(), which just
103 augments the IBuildSet.getStatusSummaryForBuilds() method to include the
104@@ -1530,9 +1539,15 @@
105 >>> cprov_published_sources.count()
106 4
107
108- >>> len(list(decorated_set))
109+ >>> decorated_sources_list = list(decorated_set)
110+ >>> len(decorated_sources_list)
111 4
112
113+The objects loaded have their newer_distroseries_version preloaded.
114+
115+ >>> actual_pub = decorated_sources_list[0].context
116+ >>> get_property_cache(actual_pub).newer_distroseries_version
117+
118 The decorated objects are returned in the same order used in the given
119 'source_publications'.
120
121
122=== modified file 'lib/lp/soyuz/model/publishing.py'
123--- lib/lp/soyuz/model/publishing.py 2010-10-17 03:45:49 +0000
124+++ lib/lp/soyuz/model/publishing.py 2010-11-03 17:51:56 +0000
125@@ -71,6 +71,10 @@
126 from lp.buildmaster.model.packagebuild import PackageBuild
127 from lp.registry.interfaces.person import validate_public_person
128 from lp.registry.interfaces.pocket import PackagePublishingPocket
129+from lp.services.propertycache import (
130+ cachedproperty,
131+ get_property_cache,
132+ )
133 from lp.services.worlddata.model.country import Country
134 from lp.soyuz.enums import (
135 BinaryPackageFormat,
136@@ -445,18 +449,11 @@
137 return self.sourcepackagerelease.dscsigningkey.owner
138 return None
139
140- @property
141+ @cachedproperty
142 def newer_distroseries_version(self):
143 """See `ISourcePackagePublishingHistory`."""
144- latest_releases = self.distroseries.getCurrentSourceReleases(
145- [self.sourcepackagerelease.sourcepackagename])
146- latest_release = latest_releases.get(self.meta_sourcepackage, None)
147-
148- if latest_release is not None and apt_pkg.VersionCompare(
149- latest_release.version, self.source_package_version) > 0:
150- return latest_release
151- else:
152- return None
153+ self.distroseries.setNewerDistroSeriesVersions([self])
154+ return get_property_cache(self).newer_distroseries_version
155
156 def getPublishedBinaries(self):
157 """See `ISourcePackagePublishingHistory`."""