Merge lp:~stevenk/launchpad/moar-preload-distroseries-queue-redux into lp:launchpad

Proposed by Steve Kowalik
Status: Merged
Approved by: Steve Kowalik
Approved revision: no longer in the source branch.
Merged at revision: 16410
Proposed branch: lp:~stevenk/launchpad/moar-preload-distroseries-queue-redux
Merge into: lp:launchpad
Diff against target: 783 lines (+155/-312)
11 files modified
lib/lp/soyuz/browser/queue.py (+32/-39)
lib/lp/soyuz/browser/tests/test_queue.py (+20/-3)
lib/lp/soyuz/configure.zcml (+1/-13)
lib/lp/soyuz/doc/soyuz-files.txt (+56/-124)
lib/lp/soyuz/interfaces/files.py (+1/-25)
lib/lp/soyuz/interfaces/queue.py (+1/-4)
lib/lp/soyuz/model/files.py (+2/-60)
lib/lp/soyuz/model/queue.py (+27/-13)
lib/lp/soyuz/model/sourcepackagerelease.py (+13/-3)
lib/lp/soyuz/tests/test_binarypackagefile.py (+0/-26)
lib/lp/soyuz/tests/test_packageupload.py (+2/-2)
To merge this branch: bzr merge lp:~stevenk/launchpad/moar-preload-distroseries-queue-redux
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+142056@code.launchpad.net

Commit message

More preloading for IPackageUploadSet.getAll(), including the demise of I{Binary,SourcePackage}ReleaseFileSet and IPackageUpload.getSourceBySourcePackageReleaseIDs().

Description of the change

Preload all the things for IPackageUploadSet.getAll().

Turn ISourcePackageRelease.package_diffs into a cachedproperty, invalidate it when requestDiffTo is called and set it inside the preloading magic for IPackageUploadSet.getAll().

Rip apart the preloading for SPRF and BPF to make use of load_referencing and load_related, which allows both I{Binary,SourcePackage}ReleaseFileSet and its tests to all be consigned to a watery grave.

Also rewrite one of the internal functions that crafted a dictionary of SPR ID to PUS to not make use of IPackageUpload.getSourceBySourcePackageReleaseIDs(), so delete that too, since not even tests made use of it.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/soyuz/browser/queue.py'
2--- lib/lp/soyuz/browser/queue.py 2013-01-02 22:59:10 +0000
3+++ lib/lp/soyuz/browser/queue.py 2013-01-08 05:53:51 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2013 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 """Browser views for package queue."""
10@@ -27,6 +27,10 @@
11 )
12 from lp.services.job.model.job import Job
13 from lp.services.librarian.browser import FileNavigationMixin
14+from lp.services.librarian.model import (
15+ LibraryFileAlias,
16+ LibraryFileContent,
17+ )
18 from lp.services.webapp import (
19 GetitemNavigation,
20 LaunchpadView,
21@@ -41,10 +45,6 @@
22 from lp.soyuz.interfaces.archivepermission import IArchivePermissionSet
23 from lp.soyuz.interfaces.binarypackagename import IBinaryPackageNameSet
24 from lp.soyuz.interfaces.component import IComponentSet
25-from lp.soyuz.interfaces.files import (
26- IBinaryPackageFileSet,
27- ISourcePackageReleaseFileSet,
28- )
29 from lp.soyuz.interfaces.packageset import IPackagesetSet
30 from lp.soyuz.interfaces.publishing import name_priority_map
31 from lp.soyuz.interfaces.queue import (
32@@ -55,10 +55,17 @@
33 )
34 from lp.soyuz.interfaces.section import ISectionSet
35 from lp.soyuz.model.archive import Archive
36-from lp.soyuz.model.component import Component
37+from lp.soyuz.model.binarypackagebuild import BinaryPackageBuild
38+from lp.soyuz.model.binarypackagerelease import BinaryPackageRelease
39+from lp.soyuz.model.files import (
40+ BinaryPackageFile,
41+ SourcePackageReleaseFile,
42+ )
43 from lp.soyuz.model.packagecopyjob import PackageCopyJob
44-from lp.soyuz.model.queue import PackageUploadSource
45-from lp.soyuz.model.section import Section
46+from lp.soyuz.model.queue import (
47+ PackageUploadBuild,
48+ PackageUploadSource,
49+ )
50 from lp.soyuz.model.sourcepackagerelease import SourcePackageRelease
51
52
53@@ -152,24 +159,6 @@
54 build_upload_files[upload_id].append(binary_file)
55 return build_upload_files, binary_package_names
56
57- def source_dict(self, upload_ids, source_files):
58- """Return a dictionary of PackageUploadSource keyed on SPR ID.
59-
60- :param upload_ids: A list of PackageUpload IDs.
61- """
62- sourcepackagerelease_ids = [
63- source_file.sourcepackagerelease.id
64- for source_file in source_files]
65-
66- upload_set = getUtility(IPackageUploadSet)
67- pkg_upload_sources = upload_set.getSourceBySourcePackageReleaseIDs(
68- sourcepackagerelease_ids)
69- package_upload_source_dict = {}
70- for pkg_upload_source in pkg_upload_sources:
71- package_upload_source_dict[
72- pkg_upload_source.sourcepackagerelease.id] = pkg_upload_source
73- return package_upload_source_dict
74-
75 def source_files_dict(self, package_upload_source_dict, source_files):
76 """Return a dictionary of source files keyed on PackageUpload ID."""
77 source_upload_files = {}
78@@ -226,19 +215,22 @@
79 return None
80
81 upload_ids = [upload.id for upload in uploads]
82- binary_file_set = getUtility(IBinaryPackageFileSet)
83- binary_files = list(binary_file_set.getByPackageUploadIDs(upload_ids))
84- binary_file_set.loadLibraryFiles(binary_files)
85- packageuploadsources = load_referencing(
86+ puses = load_referencing(
87 PackageUploadSource, uploads, ['packageuploadID'])
88- source_file_set = getUtility(ISourcePackageReleaseFileSet)
89- source_files = list(source_file_set.getByPackageUploadIDs(upload_ids))
90+ pubs = load_referencing(
91+ PackageUploadBuild, uploads, ['packageuploadID'])
92+
93 source_sprs = load_related(
94- SourcePackageRelease, packageuploadsources,
95- ['sourcepackagereleaseID'])
96-
97- load_related(Section, source_sprs, ['sectionID'])
98- load_related(Component, source_sprs, ['componentID'])
99+ SourcePackageRelease, puses, ['sourcepackagereleaseID'])
100+ bpbs = load_related(BinaryPackageBuild, pubs, ['buildID'])
101+ bprs = load_referencing(BinaryPackageRelease, bpbs, ['buildID'])
102+ source_files = load_referencing(
103+ SourcePackageReleaseFile, source_sprs, ['sourcepackagereleaseID'])
104+ binary_files = load_referencing(
105+ BinaryPackageFile, bprs, ['binarypackagereleaseID'])
106+ file_lfas = load_related(
107+ LibraryFileAlias, source_files + binary_files, ['libraryfileID'])
108+ load_related(LibraryFileContent, file_lfas, ['contentID'])
109
110 # Get a dictionary of lists of binary files keyed by upload ID.
111 package_upload_builds_dict = self.builds_dict(upload_ids, binary_files)
112@@ -247,8 +239,9 @@
113 package_upload_builds_dict, binary_files)
114
115 # Get a dictionary of lists of source files keyed by upload ID.
116- package_upload_source_dict = self.source_dict(
117- upload_ids, source_files)
118+ package_upload_source_dict = {}
119+ for pus in puses:
120+ package_upload_source_dict[pus.sourcepackagereleaseID] = pus
121 source_upload_files = self.source_files_dict(
122 package_upload_source_dict, source_files)
123
124
125=== modified file 'lib/lp/soyuz/browser/tests/test_queue.py'
126--- lib/lp/soyuz/browser/tests/test_queue.py 2013-01-02 22:59:10 +0000
127+++ lib/lp/soyuz/browser/tests/test_queue.py 2013-01-08 05:53:51 +0000
128@@ -1,4 +1,4 @@
129-# Copyright 2010-2012 Canonical Ltd. This software is licensed under the
130+# Copyright 2010-2013 Canonical Ltd. This software is licensed under the
131 # GNU Affero General Public License version 3 (see the file LICENSE).
132
133 """Unit tests for QueueItemsView."""
134@@ -368,20 +368,37 @@
135 def test_query_count(self):
136 login(ADMIN_EMAIL)
137 uploads = []
138+ sprs = []
139 distroseries = self.factory.makeDistroSeries()
140+ dsc = self.factory.makeLibraryFileAlias(filename='foo_0.1.dsc')
141+ deb = self.factory.makeLibraryFileAlias(filename='foo.deb')
142+ transaction.commit()
143 for i in range(5):
144 uploads.append(self.factory.makeSourcePackageUpload(distroseries))
145+ sprs.append(uploads[-1].sources[0].sourcepackagerelease)
146+ sprs[-1].addFile(dsc)
147 uploads.append(self.factory.makeCustomPackageUpload(distroseries))
148 uploads.append(self.factory.makeCopyJobPackageUpload(distroseries))
149+ self.factory.makePackageset(
150+ packages=(sprs[0].sourcepackagename, sprs[2].sourcepackagename,
151+ sprs[4].sourcepackagename),
152+ distroseries=distroseries)
153+ self.factory.makePackageset(
154+ packages=(sprs[1].sourcepackagename,), distroseries=distroseries)
155+ self.factory.makePackageset(
156+ packages=(sprs[3].sourcepackagename,), distroseries=distroseries)
157+ for i in (0, 2, 3):
158+ self.factory.makePackageDiff(to_source=sprs[i])
159 for i in range(15):
160 uploads.append(self.factory.makeBuildPackageUpload(distroseries))
161+ uploads[-1].builds[0].build.binarypackages[0].addFile(deb)
162 queue_admin = self.factory.makeArchiveAdmin(distroseries.main_archive)
163 Store.of(uploads[0]).invalidate()
164 with person_logged_in(queue_admin):
165 with StormStatementRecorder() as recorder:
166 view = self.makeView(distroseries, queue_admin)
167- view()
168- self.assertThat(recorder, HasQueryCount(Equals(52)))
169+ view()
170+ self.assertThat(recorder, HasQueryCount(Equals(55)))
171
172
173 class TestCompletePackageUpload(TestCaseWithFactory):
174
175=== modified file 'lib/lp/soyuz/configure.zcml'
176--- lib/lp/soyuz/configure.zcml 2013-01-02 06:05:27 +0000
177+++ lib/lp/soyuz/configure.zcml 2013-01-08 05:53:51 +0000
178@@ -1,4 +1,4 @@
179-<!-- Copyright 2009-2012 Canonical Ltd. This software is licensed under the
180+<!-- Copyright 2009-2013 Canonical Ltd. This software is licensed under the
181 GNU Affero General Public License version 3 (see the file LICENSE).
182 -->
183
184@@ -779,18 +779,6 @@
185 permission="launchpad.Edit"
186 set_schema="lp.soyuz.interfaces.files.IBinaryPackageFile"/>
187 </class>
188- <securedutility
189- class="lp.soyuz.model.files.BinaryPackageFileSet"
190- provides="lp.soyuz.interfaces.files.IBinaryPackageFileSet">
191- <allow
192- interface="lp.soyuz.interfaces.files.IBinaryPackageFileSet"/>
193- </securedutility>
194- <securedutility
195- class="lp.soyuz.model.files.SourcePackageReleaseFileSet"
196- provides="lp.soyuz.interfaces.files.ISourcePackageReleaseFileSet">
197- <allow
198- interface="lp.soyuz.interfaces.files.ISourcePackageReleaseFileSet"/>
199- </securedutility>
200
201 <!-- Packageset -->
202
203
204=== modified file 'lib/lp/soyuz/doc/soyuz-files.txt'
205--- lib/lp/soyuz/doc/soyuz-files.txt 2012-12-26 01:32:19 +0000
206+++ lib/lp/soyuz/doc/soyuz-files.txt 2013-01-08 05:53:51 +0000
207@@ -1,4 +1,5 @@
208-= Soyuz Files =
209+Soyuz Files
210+===========
211
212 Soyuz keeps a collection of source and binary packages classified as
213 SourcePackageRelease and BinaryPackageRelease respectively, each of
214@@ -10,20 +11,21 @@
215 SourcePackageReleaseFile or BinaryPackageFile are available via the
216 'files' attribute on its parent.
217
218- >>> from zope.component import getUtility
219- >>> from lp.testing import verifyObject
220-
221- >>> from lp.services.librarian.interfaces import ILibraryFileAlias
222- >>> from lp.registry.interfaces.distribution import IDistributionSet
223- >>> from lp.soyuz.interfaces.files import (
224- ... IBinaryPackageFile,
225- ... ISourcePackageReleaseFile,
226- ... )
227-
228- >>> warty = getUtility(IDistributionSet)['ubuntu']['warty']
229-
230-
231-== Source Files ==
232+ >>> from zope.component import getUtility
233+ >>> from lp.testing import verifyObject
234+
235+ >>> from lp.services.librarian.interfaces import ILibraryFileAlias
236+ >>> from lp.registry.interfaces.distribution import IDistributionSet
237+ >>> from lp.soyuz.interfaces.files import (
238+ ... IBinaryPackageFile,
239+ ... ISourcePackageReleaseFile,
240+ ... )
241+
242+ >>> warty = getUtility(IDistributionSet)['ubuntu']['warty']
243+
244+
245+Source Files
246+------------
247
248 An ISourcePackageRelease contains the file that make up the source
249 package for that release:
250@@ -33,118 +35,48 @@
251 upstream source.
252 * A '.dsc' package description file.
253
254- >>> warty_firefox_srcpkg = warty.getSourcePackage(
255- ... 'mozilla-firefox').currentrelease
256-
257- >>> srcfile = warty_firefox_srcpkg.files[0]
258-
259- >>> verifyObject(ISourcePackageReleaseFile, srcfile)
260- True
261-
262- >>> verifyObject(ILibraryFileAlias, srcfile.libraryfile)
263- True
264-
265- >>> srcfile.libraryfile.filename
266- u'firefox_0.9.2.orig.tar.gz'
267-
268- >>> srcfile.libraryfile.http_url
269- 'http://.../3/firefox_0.9.2.orig.tar.gz'
270-
271-
272-== Binary Files ==
273+ >>> warty_firefox_srcpkg = warty.getSourcePackage(
274+ ... 'mozilla-firefox').currentrelease
275+
276+ >>> srcfile = warty_firefox_srcpkg.files[0]
277+
278+ >>> verifyObject(ISourcePackageReleaseFile, srcfile)
279+ True
280+
281+ >>> verifyObject(ILibraryFileAlias, srcfile.libraryfile)
282+ True
283+
284+ >>> srcfile.libraryfile.filename
285+ u'firefox_0.9.2.orig.tar.gz'
286+
287+ >>> srcfile.libraryfile.http_url
288+ 'http://.../3/firefox_0.9.2.orig.tar.gz'
289+
290+
291+Binary Files
292+------------
293
294 An IBinaryPackageRelease contains only one file which is the
295 instalable debian-format file:
296
297 * An '.deb'
298
299- >>> warty_i386_pmount_binpkg = warty['i386'].getBinaryPackage(
300- ... 'pmount')['2:1.9-1']
301-
302- >>> warty_i386_pmount_binpkg.name
303- u'pmount'
304-
305- >>> debfile = warty_i386_pmount_binpkg.files[0]
306-
307- >>> verifyObject(IBinaryPackageFile, debfile)
308- True
309-
310- >>> verifyObject(ILibraryFileAlias, debfile.libraryfile)
311- True
312-
313- >>> debfile.libraryfile.filename
314- u'pmount_1.9-1_all.deb'
315-
316- >>> debfile.libraryfile.http_url
317- 'http://.../37/pmount_1.9-1_all.deb'
318-
319-
320-== Utilities ==
321-
322-There is a utility class IBinaryPackageFileSet that will return
323-BinaryPackageFile records.
324-
325- >>> from lp.soyuz.interfaces.files import (
326- ... IBinaryPackageFileSet)
327- >>> file_set = getUtility(IBinaryPackageFileSet)
328-
329-It only contains one method, getByPackageUploadIDs(), that will return
330-all the BinaryPackageFiles that are associated with the supplied
331-PackageUpload IDs.
332-
333- >>> ids = (2,)
334- >>> binary_package_files = file_set.getByPackageUploadIDs(ids)
335- >>> for binary_package_file in binary_package_files:
336- ... print binary_package_file.libraryfile.filename
337- pmount_1.0-1_all.deb
338-
339-Additional IDs may also be passed and if they don't have any
340-BinaryPackageFiles they are ignored and don't affect the results.
341-
342- >>> ids = (1,2,3,4,5)
343- >>> binary_package_files = file_set.getByPackageUploadIDs(ids)
344- >>> for binary_package_file in binary_package_files:
345- ... print binary_package_file.libraryfile.filename
346- pmount_1.0-1_all.deb
347-
348-If no IDs or None is passed, an empty list is returned.
349-
350- >>> file_set.getByPackageUploadIDs([])
351- []
352-
353- >>> file_set.getByPackageUploadIDs(None)
354- []
355-
356-There is also a utility called SourcePackageReleaseFileSet which has the
357-same method, getByPackageUploadIDs(), and performs the same function.
358-
359- >>> import operator
360- >>> from lp.soyuz.interfaces.files import (
361- ... ISourcePackageReleaseFileSet)
362- >>> source_file_set = getUtility(ISourcePackageReleaseFileSet)
363- >>> ids = (15,)
364- >>> source_files = source_file_set.getByPackageUploadIDs(ids)
365- >>> for source_file in sorted(source_files,
366- ... key=operator.attrgetter('id')):
367- ... print source_file.libraryfile.filename
368- firefox_0.9.2.orig.tar.gz
369- iceweasel-1.0.dsc
370-
371-As with the same method for binary files, it will ignore IDs for which
372-there are no uploads:
373-
374- >>> ids = (14, 15)
375- >>> source_files = source_file_set.getByPackageUploadIDs(ids)
376- >>> for source_file in sorted(source_files,
377- ... key=operator.attrgetter('id')):
378- ... print source_file.libraryfile.filename
379- firefox_0.9.2.orig.tar.gz
380- iceweasel-1.0.dsc
381-
382-If no IDs or None is passed, an empty list is returned.
383-
384- >>> source_file_set.getByPackageUploadIDs([])
385- []
386-
387- >>> source_file_set.getByPackageUploadIDs(None)
388- []
389+ >>> warty_i386_pmount_binpkg = warty['i386'].getBinaryPackage(
390+ ... 'pmount')['2:1.9-1']
391+
392+ >>> warty_i386_pmount_binpkg.name
393+ u'pmount'
394+
395+ >>> debfile = warty_i386_pmount_binpkg.files[0]
396+
397+ >>> verifyObject(IBinaryPackageFile, debfile)
398+ True
399+
400+ >>> verifyObject(ILibraryFileAlias, debfile.libraryfile)
401+ True
402+
403+ >>> debfile.libraryfile.filename
404+ u'pmount_1.9-1_all.deb'
405+
406+ >>> debfile.libraryfile.http_url
407+ 'http://.../37/pmount_1.9-1_all.deb'
408
409=== modified file 'lib/lp/soyuz/interfaces/files.py'
410--- lib/lp/soyuz/interfaces/files.py 2013-01-07 02:40:55 +0000
411+++ lib/lp/soyuz/interfaces/files.py 2013-01-08 05:53:51 +0000
412@@ -1,4 +1,4 @@
413-# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
414+# Copyright 2009-2013 Canonical Ltd. This software is licensed under the
415 # GNU Affero General Public License version 3 (see the file LICENSE).
416
417 """Package file interfaces."""
418@@ -7,9 +7,7 @@
419
420 __all__ = [
421 'IBinaryPackageFile',
422- 'IBinaryPackageFileSet',
423 'ISourcePackageReleaseFile',
424- 'ISourcePackageReleaseFileSet',
425 ]
426
427 from lazr.restful.fields import Reference
428@@ -48,21 +46,6 @@
429 )
430
431
432-class IBinaryPackageFileSet(Interface):
433- """The set of all `BinaryPackageFile`s."""
434-
435- def getByPackageUploadIDs(package_upload_ids):
436- """Return `BinaryPackageFile`s for the `PackageUpload` IDs."""
437-
438- def loadLibraryFiles(binary_files):
439- """Bulk-load Librarian files associated with `binary_files`.
440-
441- This loads the `LibraryFileAlias` and `LibraryFileContent` for each
442- of `binary_files` into the ORM cache, and returns an iterable of
443- `LibraryFileAlias`.
444- """
445-
446-
447 class ISourcePackageReleaseFile(Interface):
448 """A source package release to librarian link record."""
449
450@@ -93,10 +76,3 @@
451 title=_('Whether this file is an original tarball'),
452 required=True, readonly=False,
453 )
454-
455-
456-class ISourcePackageReleaseFileSet(Interface):
457- """The set of all `SourcePackageRelease`s."""
458-
459- def getByPackageUploadIDs(package_upload_ids):
460- """Return `SourcePackageReleaseFile`s for the `PackageUpload` IDs."""
461
462=== modified file 'lib/lp/soyuz/interfaces/queue.py'
463--- lib/lp/soyuz/interfaces/queue.py 2012-12-10 06:27:12 +0000
464+++ lib/lp/soyuz/interfaces/queue.py 2013-01-08 05:53:51 +0000
465@@ -1,4 +1,4 @@
466-# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
467+# Copyright 2009-2013 Canonical Ltd. This software is licensed under the
468 # GNU Affero General Public License version 3 (see the file LICENSE).
469
470 """Queue interfaces."""
471@@ -775,9 +775,6 @@
472 def getBuildByBuildIDs(build_ids):
473 """Return `PackageUploadBuilds`s for the supplied build IDs."""
474
475- def getSourceBySourcePackageReleaseIDs(spr_ids):
476- """Return `PackageUploadSource`s for the sourcepackagerelease IDs."""
477-
478 def getByPackageCopyJobIDs(pcj_ids):
479 """Return `PackageUpload`s using `PackageCopyJob`s.
480
481
482=== modified file 'lib/lp/soyuz/model/files.py'
483--- lib/lp/soyuz/model/files.py 2013-01-07 02:40:55 +0000
484+++ lib/lp/soyuz/model/files.py 2013-01-08 05:53:51 +0000
485@@ -1,10 +1,9 @@
486-# Copyright 2009 Canonical Ltd. This software is licensed under the
487+# Copyright 2009-2013 Canonical Ltd. This software is licensed under the
488 # GNU Affero General Public License version 3 (see the file LICENSE).
489
490 __metaclass__ = type
491 __all__ = [
492 'BinaryPackageFile',
493- 'BinaryPackageFileSet',
494 'SourceFileMixin',
495 'SourcePackageReleaseFile',
496 ]
497@@ -13,22 +12,12 @@
498 from zope.interface import implements
499
500 from lp.registry.interfaces.sourcepackage import SourcePackageFileType
501-from lp.services.database.bulk import load_related
502 from lp.services.database.enumcol import EnumCol
503-from lp.services.database.sqlbase import (
504- SQLBase,
505- sqlvalues,
506- )
507-from lp.services.librarian.model import (
508- LibraryFileAlias,
509- LibraryFileContent,
510- )
511+from lp.services.database.sqlbase import SQLBase
512 from lp.soyuz.enums import BinaryPackageFileType
513 from lp.soyuz.interfaces.files import (
514 IBinaryPackageFile,
515- IBinaryPackageFileSet,
516 ISourcePackageReleaseFile,
517- ISourcePackageReleaseFileSet,
518 )
519
520
521@@ -46,33 +35,6 @@
522 schema=BinaryPackageFileType)
523
524
525-class BinaryPackageFileSet:
526- """See `IBinaryPackageFileSet`."""
527- implements(IBinaryPackageFileSet)
528-
529- def getByPackageUploadIDs(self, package_upload_ids):
530- """See `IBinaryPackageFileSet`."""
531- if package_upload_ids is None or len(package_upload_ids) == 0:
532- return []
533- return BinaryPackageFile.select("""
534- PackageUploadBuild.packageupload = PackageUpload.id AND
535- PackageUpload.id IN %s AND
536- BinaryPackageBuild.id = PackageUploadBuild.build AND
537- BinaryPackageRelease.build = BinaryPackageBuild.id AND
538- BinaryPackageFile.binarypackagerelease = BinaryPackageRelease.id
539- """ % sqlvalues(package_upload_ids),
540- clauseTables=["PackageUpload", "PackageUploadBuild",
541- "BinaryPackageBuild", "BinaryPackageRelease"],
542- prejoins=["binarypackagerelease", "binarypackagerelease.build",
543- "binarypackagerelease.binarypackagename"])
544-
545- def loadLibraryFiles(self, binary_files):
546- """See `IBinaryPackageFileSet`."""
547- lfas = load_related(LibraryFileAlias, binary_files, ['libraryfileID'])
548- load_related(LibraryFileContent, lfas, ['contentID'])
549- return lfas
550-
551-
552 class SourceFileMixin:
553 """Mix-in class for common functionality between source file classes."""
554
555@@ -94,23 +56,3 @@
556 libraryfile = ForeignKey(foreignKey='LibraryFileAlias',
557 dbName='libraryfile')
558 filetype = EnumCol(schema=SourcePackageFileType)
559-
560-
561-class SourcePackageReleaseFileSet:
562- """See `ISourcePackageReleaseFileSet`."""
563- implements(ISourcePackageReleaseFileSet)
564-
565- def getByPackageUploadIDs(self, package_upload_ids):
566- """See `ISourcePackageReleaseFileSet`."""
567- if package_upload_ids is None or len(package_upload_ids) == 0:
568- return []
569- return SourcePackageReleaseFile.select("""
570- PackageUploadSource.packageupload = PackageUpload.id AND
571- PackageUpload.id IN %s AND
572- SourcePackageReleaseFile.sourcepackagerelease =
573- PackageUploadSource.sourcepackagerelease
574- """ % sqlvalues(package_upload_ids),
575- clauseTables=["PackageUpload", "PackageUploadSource"],
576- prejoins=["libraryfile", "libraryfile.content",
577- "sourcepackagerelease",
578- "sourcepackagerelease.sourcepackagename"])
579
580=== modified file 'lib/lp/soyuz/model/queue.py'
581--- lib/lp/soyuz/model/queue.py 2013-01-02 22:59:10 +0000
582+++ lib/lp/soyuz/model/queue.py 2013-01-08 05:53:51 +0000
583@@ -1,4 +1,4 @@
584-# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
585+# Copyright 2009-2013 Canonical Ltd. This software is licensed under the
586 # GNU Affero General Public License version 3 (see the file LICENSE).
587
588 __metaclass__ = type
589@@ -48,6 +48,7 @@
590 from lp.archivepublisher.customupload import CustomUploadError
591 from lp.archivepublisher.debversion import Version
592 from lp.archiveuploader.tagfiles import parse_tagfile_content
593+from lp.buildmaster.model.packagebuild import PackageBuild
594 from lp.registry.interfaces.pocket import PackagePublishingPocket
595 from lp.registry.model.sourcepackagename import SourcePackageName
596 from lp.services.auditor.client import AuditorClient
597@@ -75,7 +76,10 @@
598 from lp.services.features import getFeatureFlag
599 from lp.services.librarian.browser import ProxiedLibraryFileAlias
600 from lp.services.librarian.interfaces.client import DownloadFailed
601-from lp.services.librarian.model import LibraryFileAlias
602+from lp.services.librarian.model import (
603+ LibraryFileAlias,
604+ LibraryFileContent,
605+ )
606 from lp.services.librarian.utils import copy_and_close
607 from lp.services.mail.signedmessage import strip_pgp_signature
608 from lp.services.propertycache import (
609@@ -96,6 +100,7 @@
610 from lp.soyuz.interfaces.archivepermission import IArchivePermissionSet
611 from lp.soyuz.interfaces.component import IComponentSet
612 from lp.soyuz.interfaces.packagecopyjob import IPackageCopyJobSource
613+from lp.soyuz.interfaces.packagediff import IPackageDiffSet
614 from lp.soyuz.interfaces.publishing import (
615 IPublishingSet,
616 name_priority_map,
617@@ -115,7 +120,11 @@
618 QueueStateWriteProtectedError,
619 )
620 from lp.soyuz.interfaces.section import ISectionSet
621+from lp.soyuz.model.binarypackagename import BinaryPackageName
622+from lp.soyuz.model.binarypackagerelease import BinaryPackageRelease
623+from lp.soyuz.model.component import Component
624 from lp.soyuz.model.distroarchseries import DistroArchSeries
625+from lp.soyuz.model.section import Section
626 from lp.soyuz.pas import BuildDaemonPackagesArchSpecific
627
628 # There are imports below in PackageUploadCustom for various bits
629@@ -1683,17 +1692,8 @@
630 """See `IPackageUploadSet`."""
631 if build_ids is None or len(build_ids) == 0:
632 return []
633- return PackageUploadBuild.select("""
634- PackageUploadBuild.build IN %s
635- """ % sqlvalues(build_ids))
636-
637- def getSourceBySourcePackageReleaseIDs(self, spr_ids):
638- """See `IPackageUploadSet`."""
639- if spr_ids is None or len(spr_ids) == 0:
640- return []
641- return PackageUploadSource.select("""
642- PackageUploadSource.sourcepackagerelease IN %s
643- """ % sqlvalues(spr_ids))
644+ return PackageUploadBuild.select(
645+ "PackageUploadBuild.build IN %s" % sqlvalues(build_ids))
646
647 def getByPackageCopyJobIDs(self, pcj_ids):
648 """See `IPackageUploadSet`."""
649@@ -1728,18 +1728,32 @@
650 source_sprs = load_related(
651 SourcePackageRelease, puses, ['sourcepackagereleaseID'])
652 bpbs = load_related(BinaryPackageBuild, pubs, ['buildID'])
653+ load_related(PackageBuild, bpbs, ['package_build_id'])
654 load_related(DistroArchSeries, bpbs, ['distro_arch_series_id'])
655 binary_sprs = load_related(
656 SourcePackageRelease, bpbs, ['source_package_release_id'])
657+ bprs = load_referencing(BinaryPackageRelease, bpbs, ['buildID'])
658+ load_related(BinaryPackageName, bprs, ['binarypackagenameID'])
659 sprs = source_sprs + binary_sprs
660
661 load_related(SourcePackageName, sprs, ['sourcepackagenameID'])
662+ load_related(Section, sprs + bprs, ['sectionID'])
663+ load_related(Component, sprs, ['componentID'])
664 load_related(LibraryFileAlias, uploads, ['changes_file_id'])
665 publications = load_referencing(
666 SourcePackagePublishingHistory, sprs, ['sourcepackagereleaseID'])
667 load_related(Archive, publications, ['archiveID'])
668+ diffs = getUtility(IPackageDiffSet).getDiffsToReleases(
669+ sprs, preload_for_display=True)
670+
671+ puc_lfas = load_related(LibraryFileAlias, pucs, ['libraryfilealiasID'])
672+ load_related(LibraryFileContent, puc_lfas, ['contentID'])
673+
674 for spr_cache in sprs:
675 get_property_cache(spr_cache).published_archives = []
676+ get_property_cache(spr_cache).package_diffs = []
677 for publication in publications:
678 spr_cache = get_property_cache(publication.sourcepackagerelease)
679 spr_cache.published_archives.append(publication.archive)
680+ for diff in diffs:
681+ get_property_cache(diff.to_source).package_diffs.append(diff)
682
683=== modified file 'lib/lp/soyuz/model/sourcepackagerelease.py'
684--- lib/lp/soyuz/model/sourcepackagerelease.py 2013-01-02 22:59:10 +0000
685+++ lib/lp/soyuz/model/sourcepackagerelease.py 2013-01-08 05:53:51 +0000
686@@ -30,6 +30,7 @@
687 from storm.info import ClassAlias
688 from storm.locals import (
689 Int,
690+ Desc,
691 Reference,
692 )
693 from storm.store import Store
694@@ -59,7 +60,10 @@
695 LibraryFileAlias,
696 LibraryFileContent,
697 )
698-from lp.services.propertycache import cachedproperty
699+from lp.services.propertycache import (
700+ cachedproperty,
701+ get_property_cache,
702+ )
703 from lp.soyuz.enums import PackageDiffStatus
704 from lp.soyuz.interfaces.archive import MAIN_ARCHIVE_PURPOSES
705 from lp.soyuz.interfaces.binarypackagebuild import IBinaryPackageBuildSet
706@@ -165,8 +169,6 @@
707 joinColumn='sourcepackagerelease', orderBy="libraryfile")
708 publishings = SQLMultipleJoin('SourcePackagePublishingHistory',
709 joinColumn='sourcepackagerelease', orderBy="-datecreated")
710- package_diffs = SQLMultipleJoin(
711- 'PackageDiff', joinColumn='to_source', orderBy="-date_requested")
712
713 _user_defined_fields = StringCol(dbName='user_defined_fields')
714
715@@ -209,6 +211,12 @@
716 return []
717 return simplejson.loads(self._user_defined_fields)
718
719+ @cachedproperty
720+ def package_diffs(self):
721+ return list(Store.of(self).find(
722+ PackageDiff, to_source=self).order_by(
723+ Desc(PackageDiff.date_requested)))
724+
725 @property
726 def builds(self):
727 """See `ISourcePackageRelease`."""
728@@ -584,6 +592,8 @@
729 else:
730 status = PackageDiffStatus.PENDING
731
732+ Store.of(to_sourcepackagerelease).flush()
733+ del get_property_cache(to_sourcepackagerelease).package_diffs
734 return PackageDiff(
735 from_source=self, to_source=to_sourcepackagerelease,
736 requester=requester, status=status)
737
738=== removed file 'lib/lp/soyuz/tests/test_binarypackagefile.py'
739--- lib/lp/soyuz/tests/test_binarypackagefile.py 2012-01-01 02:58:52 +0000
740+++ lib/lp/soyuz/tests/test_binarypackagefile.py 1970-01-01 00:00:00 +0000
741@@ -1,26 +0,0 @@
742-# Copyright 2011 Canonical Ltd. This software is licensed under the
743-# GNU Affero General Public License version 3 (see the file LICENSE).
744-
745-"""Unit tests for `IBinaryPackageFile` and `IBinaryPackageFileSet`."""
746-
747-__metaclass__ = type
748-
749-from zope.component import getUtility
750-
751-from lp.soyuz.interfaces.files import IBinaryPackageFileSet
752-from lp.testing import TestCaseWithFactory
753-from lp.testing.layers import LaunchpadZopelessLayer
754-from lp.testing.matchers import Provides
755-
756-
757-class TestBinaryPackageFileSet(TestCaseWithFactory):
758- layer = LaunchpadZopelessLayer
759-
760- def test_implements_interface(self):
761- file_set = getUtility(IBinaryPackageFileSet)
762- self.assertThat(file_set, Provides(IBinaryPackageFileSet))
763-
764- def test_loadLibraryFiles_returns_associated_lfas(self):
765- bpf = self.factory.makeBinaryPackageFile()
766- lfas = getUtility(IBinaryPackageFileSet).loadLibraryFiles([bpf])
767- self.assertContentEqual([bpf.libraryfile], lfas)
768
769=== modified file 'lib/lp/soyuz/tests/test_packageupload.py'
770--- lib/lp/soyuz/tests/test_packageupload.py 2013-01-02 06:26:34 +0000
771+++ lib/lp/soyuz/tests/test_packageupload.py 2013-01-08 05:53:51 +0000
772@@ -1,4 +1,4 @@
773-# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
774+# Copyright 2009-2013 Canonical Ltd. This software is licensed under the
775 # GNU Affero General Public License version 3 (see the file LICENSE).
776
777 """Test Build features."""
778@@ -1304,4 +1304,4 @@
779 IStore(uploads[0].__class__).invalidate()
780 with StormStatementRecorder() as recorder:
781 ws_distroseries.getPackageUploads()
782- self.assertThat(recorder, HasQueryCount(Equals(27)))
783+ self.assertThat(recorder, HasQueryCount(Equals(33)))