Merge lp:~wgrant/launchpad/bug-1635126 into lp:launchpad

Proposed by William Grant
Status: Merged
Merged at revision: 18246
Proposed branch: lp:~wgrant/launchpad/bug-1635126
Merge into: lp:launchpad
Diff against target: 96 lines (+37/-4)
3 files modified
lib/lp/soyuz/browser/tests/test_archive_webservice.py (+17/-0)
lib/lp/soyuz/interfaces/archive.py (+4/-2)
lib/lp/soyuz/model/archive.py (+16/-2)
To merge this branch: bzr merge lp:~wgrant/launchpad/bug-1635126
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+308915@code.launchpad.net

Commit message

Fix Archive.getPublishedBinaries API call to have a constant query count.

Description of the change

Fix Archive.getPublishedBinaries API call to have a constant query count.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
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/browser/tests/test_archive_webservice.py'
2--- lib/lp/soyuz/browser/tests/test_archive_webservice.py 2015-11-26 15:46:38 +0000
3+++ lib/lp/soyuz/browser/tests/test_archive_webservice.py 2016-10-20 12:00:42 +0000
4@@ -526,6 +526,23 @@
5 publications = ws_archive.getPublishedBinaries(ordered=False)
6 self.assertEqual(2, len(publications))
7
8+ def test_getPublishedBinaries_query_count(self):
9+ # getPublishedBinaries has a query count constant in the number of
10+ # packages returned.
11+ archive_url = api_url(self.archive)
12+
13+ def create_bpph():
14+ with admin_logged_in():
15+ self.factory.makeBinaryPackagePublishingHistory(
16+ archive=self.archive)
17+
18+ def get_binaries():
19+ LaunchpadWebServiceCaller('consumer', '').named_get(
20+ archive_url, 'getPublishedBinaries').jsonBody()
21+
22+ recorder1, recorder2 = record_two_runs(get_binaries, create_bpph, 1)
23+ self.assertThat(recorder2, HasQueryCount.byEquality(recorder1))
24+
25
26 class TestremoveCopyNotification(WebServiceTestCase):
27 """Test removeCopyNotification."""
28
29=== modified file 'lib/lp/soyuz/interfaces/archive.py'
30--- lib/lp/soyuz/interfaces/archive.py 2016-07-14 18:18:13 +0000
31+++ lib/lp/soyuz/interfaces/archive.py 2016-10-20 12:00:42 +0000
32@@ -1157,6 +1157,7 @@
33 "for this PPA or None if there is no signing "
34 "key available.")))
35
36+ @call_with(eager_load=True)
37 @rename_parameters_as(
38 name="binary_name", distroarchseries="distro_arch_series")
39 @operation_parameters(
40@@ -1199,7 +1200,7 @@
41 "publications since their last run."),
42 required=False),
43 )
44- # Really returns ISourcePackagePublishingHistory, see below for
45+ # Really returns IBinaryPackagePublishingHistory, see below for
46 # patch to avoid circular import.
47 @operation_returns_collection_of(Interface)
48 @export_operation_as("getPublishedBinaries")
49@@ -1207,7 +1208,8 @@
50 def getAllPublishedBinaries(name=None, version=None, status=None,
51 distroarchseries=None, pocket=None,
52 exact_match=False, created_since_date=None,
53- ordered=True, order_by_date=False):
54+ ordered=True, order_by_date=False,
55+ eager_load=False):
56 """All `IBinaryPackagePublishingHistory` target to this archive.
57
58 :param name: binary name filter (exact match or SQL LIKE controlled
59
60=== modified file 'lib/lp/soyuz/model/archive.py'
61--- lib/lp/soyuz/model/archive.py 2016-07-29 06:49:41 +0000
62+++ lib/lp/soyuz/model/archive.py 2016-10-20 12:00:42 +0000
63@@ -865,7 +865,7 @@
64 distroarchseries=None, pocket=None,
65 exact_match=False, created_since_date=None,
66 ordered=True, order_by_date=False,
67- include_removed=True):
68+ include_removed=True, eager_load=False):
69 """See `IArchive`."""
70 clauses, order_by = self._getBinaryPublishingBaseClauses(
71 name=name, version=version, status=status, pocket=pocket,
72@@ -873,9 +873,23 @@
73 created_since_date=created_since_date, ordered=ordered,
74 order_by_date=order_by_date, include_removed=include_removed)
75
76- return Store.of(self).find(
77+ result = Store.of(self).find(
78 BinaryPackagePublishingHistory, *clauses).order_by(*order_by)
79
80+ def eager_load_api(bpphs):
81+ bprs = load_related(
82+ BinaryPackageRelease, bpphs, ['binarypackagereleaseID'])
83+ load_related(BinaryPackageName, bprs, ['binarypackagenameID'])
84+ bpbs = load_related(BinaryPackageBuild, bprs, ['buildID'])
85+ sprs = load_related(
86+ SourcePackageRelease, bpbs, ['source_package_release_id'])
87+ load_related(SourcePackageName, sprs, ['sourcepackagenameID'])
88+ load_related(Component, bpphs, ['componentID'])
89+ load_related(Section, bpphs, ['sectionID'])
90+ if eager_load:
91+ result = DecoratedResultSet(result, pre_iter_hook=eager_load_api)
92+ return result
93+
94 def getPublishedOnDiskBinaries(self, name=None, version=None, status=None,
95 distroarchseries=None, pocket=None,
96 exact_match=False):