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
1=== modified file 'lib/lp/soyuz/adapters/archivesourcepublication.py'
2--- lib/lp/soyuz/adapters/archivesourcepublication.py 2010-12-02 16:13:51 +0000
3+++ lib/lp/soyuz/adapters/archivesourcepublication.py 2011-03-21 10:51:01 +0000
4@@ -56,10 +56,8 @@
5 """
6 delegates(ISourcePackagePublishingHistory)
7
8- def __init__(self, context, unpublished_builds, builds, changesfile, status_summary):
9+ def __init__(self, context, changesfile, status_summary):
10 self.context = context
11- self._unpublished_builds = unpublished_builds
12- self._builds = builds
13 self._changesfile = changesfile
14 self._status_summary = status_summary
15
16@@ -73,19 +71,6 @@
17 return ArchiveSourcePackageRelease(
18 self.context.sourcepackagerelease, changesfile)
19
20- def getUnpublishedBuilds(self, build_state='ignored'):
21- """See `ISourcePackagePublishingHistory`.
22-
23- In this cached implementation, we ignore the build_state argument
24- and simply return the unpublished builds with which we were
25- created.
26- """
27- return self._unpublished_builds
28-
29- def getBuilds(self):
30- """See `ISourcePackagePublishingHistory`."""
31- return self._builds
32-
33 def getStatusSummaryForBuilds(self):
34 """See `ISourcePackagePublishingHistory`."""
35 return self._status_summary
36@@ -103,39 +88,6 @@
37 """Whether or not there are sources to be processed."""
38 return len(self._source_publications) > 0
39
40- def groupBySource(self, source_and_value_list):
41- """Group the give list of tuples as a dictionary.
42-
43- This is a common internal task for this class, it groups the given
44- list of tuples, (source, related_object), as a dictionary keyed by
45- distinct sources and pointing to a list of `relates_object`s.
46-
47- :return: a dictionary keyed by the distinct sources and pointing to
48- a list of `related_object`s in their original order.
49- """
50- source_and_values = {}
51- for source, value in source_and_value_list:
52- values = source_and_values.setdefault(source, [])
53- values.append(value)
54- return source_and_values
55-
56- def getBuildsBySource(self):
57- """Builds for all source publications."""
58- build_set = getUtility(IPublishingSet).getBuildsForSources(
59- self._source_publications)
60- source_and_builds = [
61- (source, build) for source, build, arch in build_set]
62- return self.groupBySource(source_and_builds)
63-
64- def getUnpublishedBuildsBySource(self):
65- """Unpublished builds for sources."""
66- publishing_set = getUtility(IPublishingSet)
67- build_set = publishing_set.getUnpublishedBuildsForSources(
68- self._source_publications)
69- source_and_builds = [
70- (source, build) for source, build, arch in build_set]
71- return self.groupBySource(source_and_builds)
72-
73 def getChangesFileBySource(self):
74 """Map changesfiles by their corresponding source publications."""
75 publishing_set = getUtility(IPublishingSet)
76@@ -160,8 +112,6 @@
77 # Load the extra-information for all source publications.
78 # All of this code would be better on an object representing a set of
79 # publications.
80- builds_by_source = self.getBuildsBySource()
81- unpublished_builds_by_source = self.getUnpublishedBuildsBySource()
82 changesfiles_by_source = self.getChangesFileBySource()
83 # Source package names are used by setNewerDistroSeriesVersions:
84 # batch load the used source package names.
85@@ -184,13 +134,10 @@
86
87 # Build the decorated object with the information we have.
88 for pub in self._source_publications:
89- builds = builds_by_source.get(pub, [])
90- unpublished_builds = unpublished_builds_by_source.get(pub, [])
91 changesfile = changesfiles_by_source.get(pub, None)
92 status_summary = status_summaries[pub.id]
93 complete_pub = ArchiveSourcePublication(
94- pub, unpublished_builds=unpublished_builds, builds=builds,
95- changesfile=changesfile, status_summary=status_summary)
96+ pub, changesfile=changesfile, status_summary=status_summary)
97 results.append(complete_pub)
98
99 return iter(results)
100
101=== modified file 'lib/lp/soyuz/browser/tests/test_archive_packages.py'
102--- lib/lp/soyuz/browser/tests/test_archive_packages.py 2011-03-04 05:54:40 +0000
103+++ lib/lp/soyuz/browser/tests/test_archive_packages.py 2011-03-21 10:51:01 +0000
104@@ -187,7 +187,7 @@
105 self.assertIs(None, view.specified_name_filter)
106
107 def test_source_query_counts(self):
108- query_baseline = 47
109+ query_baseline = 43
110 # Assess the baseline.
111 collector = QueryCollector()
112 collector.register()
113@@ -228,7 +228,7 @@
114 self.assertThat(collector, HasQueryCount(LessThan(expected_count)))
115
116 def test_binary_query_counts(self):
117- query_baseline = 43
118+ query_baseline = 40
119 # Assess the baseline.
120 collector = QueryCollector()
121 collector.register()
122@@ -245,8 +245,7 @@
123 archive=ppa)
124 url = canonical_url(ppa) + "/+packages"
125 browser.open(url)
126- self.assertThat(collector, HasQueryCount(
127- MatchesAny(LessThan(query_baseline), Equals(query_baseline))))
128+ self.assertThat(collector, HasQueryCount(LessThan(query_baseline)))
129 expected_count = collector.count
130 # Use all new objects - avoids caching issues invalidating the
131 # gathered metrics.
132@@ -260,5 +259,4 @@
133 archive=ppa, distroarchseries=pkg.distroarchseries)
134 url = canonical_url(ppa) + "/+packages"
135 browser.open(url)
136- self.assertThat(collector, HasQueryCount(
137- MatchesAny(Equals(expected_count), LessThan(expected_count))))
138+ self.assertThat(collector, HasQueryCount(Equals(expected_count)))
139
140=== modified file 'lib/lp/soyuz/doc/publishing.txt'
141--- lib/lp/soyuz/doc/publishing.txt 2011-03-03 00:43:44 +0000
142+++ lib/lp/soyuz/doc/publishing.txt 2011-03-21 10:51:01 +0000
143@@ -1587,11 +1587,9 @@
144 Mismatch: ...
145
146 We will check a little bit of the `ArchiveSourcePublications`
147-internals. There are three essential methods to fetch distinct
148+internals. There is one essential method to fetch distinct
149 information to be cached in the decorated objects:
150
151- * getBuildsBySource;
152- * getUnpublishedBuildsBySource;
153 * getChangesFileBySources
154
155 They exclude the extra references ('prejoins') returned from the
156@@ -1601,24 +1599,6 @@
157
158 >>> real_pub = cprov_published_sources[1]
159
160-Builds by source.
161-
162- >>> builds_by_source = decorated_set.getBuildsBySource()
163-
164- >>> compare_ids(
165- ... real_pub.getBuilds(), builds_by_source.get(real_pub, []))
166- Matches
167-
168-Unpublished builds by source.
169-
170- >>> unpublished_builds_by_source = (
171- ... decorated_set.getUnpublishedBuildsBySource())
172-
173- >>> compare_ids(
174- ... real_pub.getUnpublishedBuilds(),
175- ... unpublished_builds_by_source.get(real_pub, []))
176- Matches
177-
178 getChangesFileBySources() returns a dictionary mapping each individual
179 source package publication to its corresponding .changes file (as a
180 LibraryFileAlias).