Merge lp:~wgrant/launchpad/trim-asp into lp:launchpad

Proposed by William Grant
Status: Merged
Approved by: William Grant
Approved revision: no longer in the source branch.
Merged at revision: 12633
Proposed branch: lp:~wgrant/launchpad/trim-asp
Merge into: lp:launchpad
Diff against target: 180 lines (+7/-82)
3 files modified
lib/lp/soyuz/adapters/archivesourcepublication.py (+2/-55)
lib/lp/soyuz/browser/tests/test_archive_packages.py (+4/-6)
lib/lp/soyuz/doc/publishing.txt (+1/-21)
To merge this branch: bzr merge lp:~wgrant/launchpad/trim-asp
Reviewer Review Type Date Requested Status
Steve Kowalik (community) Approve
Review via email: mp+54152@code.launchpad.net

Commit message

[r=stevenk][no-qa] Drop getBuilds and getUnpublishedBuilds preloading from ArchiveSourcePublications. It no longer benefits getBuildStatusSummariesForSourceIdsAndArchive.

Description of the change

Several Archive views (primarily +index and +packages, but also +copy-packages and +delete-packages) decorate SPPH collections with ArchiveSourcePublications, which preloads .changes files and builds and build summaries. The build preloading was intended to make build summary calculation faster, but it no longer helps. This branch drops it, saving a couple of slow queries on each load.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/soyuz/adapters/archivesourcepublication.py'
--- lib/lp/soyuz/adapters/archivesourcepublication.py 2010-12-02 16:13:51 +0000
+++ lib/lp/soyuz/adapters/archivesourcepublication.py 2011-03-21 10:51:01 +0000
@@ -56,10 +56,8 @@
56 """56 """
57 delegates(ISourcePackagePublishingHistory)57 delegates(ISourcePackagePublishingHistory)
5858
59 def __init__(self, context, unpublished_builds, builds, changesfile, status_summary):59 def __init__(self, context, changesfile, status_summary):
60 self.context = context60 self.context = context
61 self._unpublished_builds = unpublished_builds
62 self._builds = builds
63 self._changesfile = changesfile61 self._changesfile = changesfile
64 self._status_summary = status_summary62 self._status_summary = status_summary
6563
@@ -73,19 +71,6 @@
73 return ArchiveSourcePackageRelease(71 return ArchiveSourcePackageRelease(
74 self.context.sourcepackagerelease, changesfile)72 self.context.sourcepackagerelease, changesfile)
7573
76 def getUnpublishedBuilds(self, build_state='ignored'):
77 """See `ISourcePackagePublishingHistory`.
78
79 In this cached implementation, we ignore the build_state argument
80 and simply return the unpublished builds with which we were
81 created.
82 """
83 return self._unpublished_builds
84
85 def getBuilds(self):
86 """See `ISourcePackagePublishingHistory`."""
87 return self._builds
88
89 def getStatusSummaryForBuilds(self):74 def getStatusSummaryForBuilds(self):
90 """See `ISourcePackagePublishingHistory`."""75 """See `ISourcePackagePublishingHistory`."""
91 return self._status_summary76 return self._status_summary
@@ -103,39 +88,6 @@
103 """Whether or not there are sources to be processed."""88 """Whether or not there are sources to be processed."""
104 return len(self._source_publications) > 089 return len(self._source_publications) > 0
10590
106 def groupBySource(self, source_and_value_list):
107 """Group the give list of tuples as a dictionary.
108
109 This is a common internal task for this class, it groups the given
110 list of tuples, (source, related_object), as a dictionary keyed by
111 distinct sources and pointing to a list of `relates_object`s.
112
113 :return: a dictionary keyed by the distinct sources and pointing to
114 a list of `related_object`s in their original order.
115 """
116 source_and_values = {}
117 for source, value in source_and_value_list:
118 values = source_and_values.setdefault(source, [])
119 values.append(value)
120 return source_and_values
121
122 def getBuildsBySource(self):
123 """Builds for all source publications."""
124 build_set = getUtility(IPublishingSet).getBuildsForSources(
125 self._source_publications)
126 source_and_builds = [
127 (source, build) for source, build, arch in build_set]
128 return self.groupBySource(source_and_builds)
129
130 def getUnpublishedBuildsBySource(self):
131 """Unpublished builds for sources."""
132 publishing_set = getUtility(IPublishingSet)
133 build_set = publishing_set.getUnpublishedBuildsForSources(
134 self._source_publications)
135 source_and_builds = [
136 (source, build) for source, build, arch in build_set]
137 return self.groupBySource(source_and_builds)
138
139 def getChangesFileBySource(self):91 def getChangesFileBySource(self):
140 """Map changesfiles by their corresponding source publications."""92 """Map changesfiles by their corresponding source publications."""
141 publishing_set = getUtility(IPublishingSet)93 publishing_set = getUtility(IPublishingSet)
@@ -160,8 +112,6 @@
160 # Load the extra-information for all source publications.112 # Load the extra-information for all source publications.
161 # All of this code would be better on an object representing a set of113 # All of this code would be better on an object representing a set of
162 # publications.114 # publications.
163 builds_by_source = self.getBuildsBySource()
164 unpublished_builds_by_source = self.getUnpublishedBuildsBySource()
165 changesfiles_by_source = self.getChangesFileBySource()115 changesfiles_by_source = self.getChangesFileBySource()
166 # Source package names are used by setNewerDistroSeriesVersions:116 # Source package names are used by setNewerDistroSeriesVersions:
167 # batch load the used source package names.117 # batch load the used source package names.
@@ -184,13 +134,10 @@
184134
185 # Build the decorated object with the information we have.135 # Build the decorated object with the information we have.
186 for pub in self._source_publications:136 for pub in self._source_publications:
187 builds = builds_by_source.get(pub, [])
188 unpublished_builds = unpublished_builds_by_source.get(pub, [])
189 changesfile = changesfiles_by_source.get(pub, None)137 changesfile = changesfiles_by_source.get(pub, None)
190 status_summary = status_summaries[pub.id]138 status_summary = status_summaries[pub.id]
191 complete_pub = ArchiveSourcePublication(139 complete_pub = ArchiveSourcePublication(
192 pub, unpublished_builds=unpublished_builds, builds=builds,140 pub, changesfile=changesfile, status_summary=status_summary)
193 changesfile=changesfile, status_summary=status_summary)
194 results.append(complete_pub)141 results.append(complete_pub)
195142
196 return iter(results)143 return iter(results)
197144
=== modified file 'lib/lp/soyuz/browser/tests/test_archive_packages.py'
--- lib/lp/soyuz/browser/tests/test_archive_packages.py 2011-03-04 05:54:40 +0000
+++ lib/lp/soyuz/browser/tests/test_archive_packages.py 2011-03-21 10:51:01 +0000
@@ -187,7 +187,7 @@
187 self.assertIs(None, view.specified_name_filter)187 self.assertIs(None, view.specified_name_filter)
188188
189 def test_source_query_counts(self):189 def test_source_query_counts(self):
190 query_baseline = 47190 query_baseline = 43
191 # Assess the baseline.191 # Assess the baseline.
192 collector = QueryCollector()192 collector = QueryCollector()
193 collector.register()193 collector.register()
@@ -228,7 +228,7 @@
228 self.assertThat(collector, HasQueryCount(LessThan(expected_count)))228 self.assertThat(collector, HasQueryCount(LessThan(expected_count)))
229229
230 def test_binary_query_counts(self):230 def test_binary_query_counts(self):
231 query_baseline = 43231 query_baseline = 40
232 # Assess the baseline.232 # Assess the baseline.
233 collector = QueryCollector()233 collector = QueryCollector()
234 collector.register()234 collector.register()
@@ -245,8 +245,7 @@
245 archive=ppa)245 archive=ppa)
246 url = canonical_url(ppa) + "/+packages"246 url = canonical_url(ppa) + "/+packages"
247 browser.open(url)247 browser.open(url)
248 self.assertThat(collector, HasQueryCount(248 self.assertThat(collector, HasQueryCount(LessThan(query_baseline)))
249 MatchesAny(LessThan(query_baseline), Equals(query_baseline))))
250 expected_count = collector.count249 expected_count = collector.count
251 # Use all new objects - avoids caching issues invalidating the250 # Use all new objects - avoids caching issues invalidating the
252 # gathered metrics.251 # gathered metrics.
@@ -260,5 +259,4 @@
260 archive=ppa, distroarchseries=pkg.distroarchseries)259 archive=ppa, distroarchseries=pkg.distroarchseries)
261 url = canonical_url(ppa) + "/+packages"260 url = canonical_url(ppa) + "/+packages"
262 browser.open(url)261 browser.open(url)
263 self.assertThat(collector, HasQueryCount(262 self.assertThat(collector, HasQueryCount(Equals(expected_count)))
264 MatchesAny(Equals(expected_count), LessThan(expected_count))))
265263
=== modified file 'lib/lp/soyuz/doc/publishing.txt'
--- lib/lp/soyuz/doc/publishing.txt 2011-03-03 00:43:44 +0000
+++ lib/lp/soyuz/doc/publishing.txt 2011-03-21 10:51:01 +0000
@@ -1587,11 +1587,9 @@
1587 Mismatch: ...1587 Mismatch: ...
15881588
1589We will check a little bit of the `ArchiveSourcePublications`1589We will check a little bit of the `ArchiveSourcePublications`
1590internals. There are three essential methods to fetch distinct1590internals. There is one essential method to fetch distinct
1591information to be cached in the decorated objects:1591information to be cached in the decorated objects:
15921592
1593 * getBuildsBySource;
1594 * getUnpublishedBuildsBySource;
1595 * getChangesFileBySources1593 * getChangesFileBySources
15961594
1597They exclude the extra references ('prejoins') returned from the1595They exclude the extra references ('prejoins') returned from the
@@ -1601,24 +1599,6 @@
16011599
1602 >>> real_pub = cprov_published_sources[1]1600 >>> real_pub = cprov_published_sources[1]
16031601
1604Builds by source.
1605
1606 >>> builds_by_source = decorated_set.getBuildsBySource()
1607
1608 >>> compare_ids(
1609 ... real_pub.getBuilds(), builds_by_source.get(real_pub, []))
1610 Matches
1611
1612Unpublished builds by source.
1613
1614 >>> unpublished_builds_by_source = (
1615 ... decorated_set.getUnpublishedBuildsBySource())
1616
1617 >>> compare_ids(
1618 ... real_pub.getUnpublishedBuilds(),
1619 ... unpublished_builds_by_source.get(real_pub, []))
1620 Matches
1621
1622getChangesFileBySources() returns a dictionary mapping each individual1602getChangesFileBySources() returns a dictionary mapping each individual
1623source package publication to its corresponding .changes file (as a1603source package publication to its corresponding .changes file (as a
1624LibraryFileAlias).1604LibraryFileAlias).