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
=== modified file 'lib/lp/soyuz/browser/queue.py'
--- lib/lp/soyuz/browser/queue.py 2013-01-02 22:59:10 +0000
+++ lib/lp/soyuz/browser/queue.py 2013-01-08 05:53:51 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009-2012 Canonical Ltd. This software is licensed under the1# Copyright 2009-2013 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Browser views for package queue."""4"""Browser views for package queue."""
@@ -27,6 +27,10 @@
27 )27 )
28from lp.services.job.model.job import Job28from lp.services.job.model.job import Job
29from lp.services.librarian.browser import FileNavigationMixin29from lp.services.librarian.browser import FileNavigationMixin
30from lp.services.librarian.model import (
31 LibraryFileAlias,
32 LibraryFileContent,
33 )
30from lp.services.webapp import (34from lp.services.webapp import (
31 GetitemNavigation,35 GetitemNavigation,
32 LaunchpadView,36 LaunchpadView,
@@ -41,10 +45,6 @@
41from lp.soyuz.interfaces.archivepermission import IArchivePermissionSet45from lp.soyuz.interfaces.archivepermission import IArchivePermissionSet
42from lp.soyuz.interfaces.binarypackagename import IBinaryPackageNameSet46from lp.soyuz.interfaces.binarypackagename import IBinaryPackageNameSet
43from lp.soyuz.interfaces.component import IComponentSet47from lp.soyuz.interfaces.component import IComponentSet
44from lp.soyuz.interfaces.files import (
45 IBinaryPackageFileSet,
46 ISourcePackageReleaseFileSet,
47 )
48from lp.soyuz.interfaces.packageset import IPackagesetSet48from lp.soyuz.interfaces.packageset import IPackagesetSet
49from lp.soyuz.interfaces.publishing import name_priority_map49from lp.soyuz.interfaces.publishing import name_priority_map
50from lp.soyuz.interfaces.queue import (50from lp.soyuz.interfaces.queue import (
@@ -55,10 +55,17 @@
55 )55 )
56from lp.soyuz.interfaces.section import ISectionSet56from lp.soyuz.interfaces.section import ISectionSet
57from lp.soyuz.model.archive import Archive57from lp.soyuz.model.archive import Archive
58from lp.soyuz.model.component import Component58from lp.soyuz.model.binarypackagebuild import BinaryPackageBuild
59from lp.soyuz.model.binarypackagerelease import BinaryPackageRelease
60from lp.soyuz.model.files import (
61 BinaryPackageFile,
62 SourcePackageReleaseFile,
63 )
59from lp.soyuz.model.packagecopyjob import PackageCopyJob64from lp.soyuz.model.packagecopyjob import PackageCopyJob
60from lp.soyuz.model.queue import PackageUploadSource65from lp.soyuz.model.queue import (
61from lp.soyuz.model.section import Section66 PackageUploadBuild,
67 PackageUploadSource,
68 )
62from lp.soyuz.model.sourcepackagerelease import SourcePackageRelease69from lp.soyuz.model.sourcepackagerelease import SourcePackageRelease
6370
6471
@@ -152,24 +159,6 @@
152 build_upload_files[upload_id].append(binary_file)159 build_upload_files[upload_id].append(binary_file)
153 return build_upload_files, binary_package_names160 return build_upload_files, binary_package_names
154161
155 def source_dict(self, upload_ids, source_files):
156 """Return a dictionary of PackageUploadSource keyed on SPR ID.
157
158 :param upload_ids: A list of PackageUpload IDs.
159 """
160 sourcepackagerelease_ids = [
161 source_file.sourcepackagerelease.id
162 for source_file in source_files]
163
164 upload_set = getUtility(IPackageUploadSet)
165 pkg_upload_sources = upload_set.getSourceBySourcePackageReleaseIDs(
166 sourcepackagerelease_ids)
167 package_upload_source_dict = {}
168 for pkg_upload_source in pkg_upload_sources:
169 package_upload_source_dict[
170 pkg_upload_source.sourcepackagerelease.id] = pkg_upload_source
171 return package_upload_source_dict
172
173 def source_files_dict(self, package_upload_source_dict, source_files):162 def source_files_dict(self, package_upload_source_dict, source_files):
174 """Return a dictionary of source files keyed on PackageUpload ID."""163 """Return a dictionary of source files keyed on PackageUpload ID."""
175 source_upload_files = {}164 source_upload_files = {}
@@ -226,19 +215,22 @@
226 return None215 return None
227216
228 upload_ids = [upload.id for upload in uploads]217 upload_ids = [upload.id for upload in uploads]
229 binary_file_set = getUtility(IBinaryPackageFileSet)218 puses = load_referencing(
230 binary_files = list(binary_file_set.getByPackageUploadIDs(upload_ids))
231 binary_file_set.loadLibraryFiles(binary_files)
232 packageuploadsources = load_referencing(
233 PackageUploadSource, uploads, ['packageuploadID'])219 PackageUploadSource, uploads, ['packageuploadID'])
234 source_file_set = getUtility(ISourcePackageReleaseFileSet)220 pubs = load_referencing(
235 source_files = list(source_file_set.getByPackageUploadIDs(upload_ids))221 PackageUploadBuild, uploads, ['packageuploadID'])
222
236 source_sprs = load_related(223 source_sprs = load_related(
237 SourcePackageRelease, packageuploadsources,224 SourcePackageRelease, puses, ['sourcepackagereleaseID'])
238 ['sourcepackagereleaseID'])225 bpbs = load_related(BinaryPackageBuild, pubs, ['buildID'])
239226 bprs = load_referencing(BinaryPackageRelease, bpbs, ['buildID'])
240 load_related(Section, source_sprs, ['sectionID'])227 source_files = load_referencing(
241 load_related(Component, source_sprs, ['componentID'])228 SourcePackageReleaseFile, source_sprs, ['sourcepackagereleaseID'])
229 binary_files = load_referencing(
230 BinaryPackageFile, bprs, ['binarypackagereleaseID'])
231 file_lfas = load_related(
232 LibraryFileAlias, source_files + binary_files, ['libraryfileID'])
233 load_related(LibraryFileContent, file_lfas, ['contentID'])
242234
243 # Get a dictionary of lists of binary files keyed by upload ID.235 # Get a dictionary of lists of binary files keyed by upload ID.
244 package_upload_builds_dict = self.builds_dict(upload_ids, binary_files)236 package_upload_builds_dict = self.builds_dict(upload_ids, binary_files)
@@ -247,8 +239,9 @@
247 package_upload_builds_dict, binary_files)239 package_upload_builds_dict, binary_files)
248240
249 # Get a dictionary of lists of source files keyed by upload ID.241 # Get a dictionary of lists of source files keyed by upload ID.
250 package_upload_source_dict = self.source_dict(242 package_upload_source_dict = {}
251 upload_ids, source_files)243 for pus in puses:
244 package_upload_source_dict[pus.sourcepackagereleaseID] = pus
252 source_upload_files = self.source_files_dict(245 source_upload_files = self.source_files_dict(
253 package_upload_source_dict, source_files)246 package_upload_source_dict, source_files)
254247
255248
=== modified file 'lib/lp/soyuz/browser/tests/test_queue.py'
--- lib/lp/soyuz/browser/tests/test_queue.py 2013-01-02 22:59:10 +0000
+++ lib/lp/soyuz/browser/tests/test_queue.py 2013-01-08 05:53:51 +0000
@@ -1,4 +1,4 @@
1# Copyright 2010-2012 Canonical Ltd. This software is licensed under the1# Copyright 2010-2013 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Unit tests for QueueItemsView."""4"""Unit tests for QueueItemsView."""
@@ -368,20 +368,37 @@
368 def test_query_count(self):368 def test_query_count(self):
369 login(ADMIN_EMAIL)369 login(ADMIN_EMAIL)
370 uploads = []370 uploads = []
371 sprs = []
371 distroseries = self.factory.makeDistroSeries()372 distroseries = self.factory.makeDistroSeries()
373 dsc = self.factory.makeLibraryFileAlias(filename='foo_0.1.dsc')
374 deb = self.factory.makeLibraryFileAlias(filename='foo.deb')
375 transaction.commit()
372 for i in range(5):376 for i in range(5):
373 uploads.append(self.factory.makeSourcePackageUpload(distroseries))377 uploads.append(self.factory.makeSourcePackageUpload(distroseries))
378 sprs.append(uploads[-1].sources[0].sourcepackagerelease)
379 sprs[-1].addFile(dsc)
374 uploads.append(self.factory.makeCustomPackageUpload(distroseries))380 uploads.append(self.factory.makeCustomPackageUpload(distroseries))
375 uploads.append(self.factory.makeCopyJobPackageUpload(distroseries))381 uploads.append(self.factory.makeCopyJobPackageUpload(distroseries))
382 self.factory.makePackageset(
383 packages=(sprs[0].sourcepackagename, sprs[2].sourcepackagename,
384 sprs[4].sourcepackagename),
385 distroseries=distroseries)
386 self.factory.makePackageset(
387 packages=(sprs[1].sourcepackagename,), distroseries=distroseries)
388 self.factory.makePackageset(
389 packages=(sprs[3].sourcepackagename,), distroseries=distroseries)
390 for i in (0, 2, 3):
391 self.factory.makePackageDiff(to_source=sprs[i])
376 for i in range(15):392 for i in range(15):
377 uploads.append(self.factory.makeBuildPackageUpload(distroseries))393 uploads.append(self.factory.makeBuildPackageUpload(distroseries))
394 uploads[-1].builds[0].build.binarypackages[0].addFile(deb)
378 queue_admin = self.factory.makeArchiveAdmin(distroseries.main_archive)395 queue_admin = self.factory.makeArchiveAdmin(distroseries.main_archive)
379 Store.of(uploads[0]).invalidate()396 Store.of(uploads[0]).invalidate()
380 with person_logged_in(queue_admin):397 with person_logged_in(queue_admin):
381 with StormStatementRecorder() as recorder:398 with StormStatementRecorder() as recorder:
382 view = self.makeView(distroseries, queue_admin)399 view = self.makeView(distroseries, queue_admin)
383 view() 400 view()
384 self.assertThat(recorder, HasQueryCount(Equals(52)))401 self.assertThat(recorder, HasQueryCount(Equals(55)))
385402
386403
387class TestCompletePackageUpload(TestCaseWithFactory):404class TestCompletePackageUpload(TestCaseWithFactory):
388405
=== modified file 'lib/lp/soyuz/configure.zcml'
--- lib/lp/soyuz/configure.zcml 2013-01-02 06:05:27 +0000
+++ lib/lp/soyuz/configure.zcml 2013-01-08 05:53:51 +0000
@@ -1,4 +1,4 @@
1<!-- Copyright 2009-2012 Canonical Ltd. This software is licensed under the1<!-- Copyright 2009-2013 Canonical Ltd. This software is licensed under the
2 GNU Affero General Public License version 3 (see the file LICENSE).2 GNU Affero General Public License version 3 (see the file LICENSE).
3-->3-->
44
@@ -779,18 +779,6 @@
779 permission="launchpad.Edit"779 permission="launchpad.Edit"
780 set_schema="lp.soyuz.interfaces.files.IBinaryPackageFile"/>780 set_schema="lp.soyuz.interfaces.files.IBinaryPackageFile"/>
781 </class>781 </class>
782 <securedutility
783 class="lp.soyuz.model.files.BinaryPackageFileSet"
784 provides="lp.soyuz.interfaces.files.IBinaryPackageFileSet">
785 <allow
786 interface="lp.soyuz.interfaces.files.IBinaryPackageFileSet"/>
787 </securedutility>
788 <securedutility
789 class="lp.soyuz.model.files.SourcePackageReleaseFileSet"
790 provides="lp.soyuz.interfaces.files.ISourcePackageReleaseFileSet">
791 <allow
792 interface="lp.soyuz.interfaces.files.ISourcePackageReleaseFileSet"/>
793 </securedutility>
794782
795 <!-- Packageset -->783 <!-- Packageset -->
796784
797785
=== modified file 'lib/lp/soyuz/doc/soyuz-files.txt'
--- lib/lp/soyuz/doc/soyuz-files.txt 2012-12-26 01:32:19 +0000
+++ lib/lp/soyuz/doc/soyuz-files.txt 2013-01-08 05:53:51 +0000
@@ -1,4 +1,5 @@
1= Soyuz Files =1Soyuz Files
2===========
23
3Soyuz keeps a collection of source and binary packages classified as4Soyuz keeps a collection of source and binary packages classified as
4SourcePackageRelease and BinaryPackageRelease respectively, each of5SourcePackageRelease and BinaryPackageRelease respectively, each of
@@ -10,20 +11,21 @@
10SourcePackageReleaseFile or BinaryPackageFile are available via the11SourcePackageReleaseFile or BinaryPackageFile are available via the
11'files' attribute on its parent.12'files' attribute on its parent.
1213
13 >>> from zope.component import getUtility14 >>> from zope.component import getUtility
14 >>> from lp.testing import verifyObject15 >>> from lp.testing import verifyObject
1516
16 >>> from lp.services.librarian.interfaces import ILibraryFileAlias17 >>> from lp.services.librarian.interfaces import ILibraryFileAlias
17 >>> from lp.registry.interfaces.distribution import IDistributionSet18 >>> from lp.registry.interfaces.distribution import IDistributionSet
18 >>> from lp.soyuz.interfaces.files import (19 >>> from lp.soyuz.interfaces.files import (
19 ... IBinaryPackageFile,20 ... IBinaryPackageFile,
20 ... ISourcePackageReleaseFile,21 ... ISourcePackageReleaseFile,
21 ... )22 ... )
2223
23 >>> warty = getUtility(IDistributionSet)['ubuntu']['warty']24 >>> warty = getUtility(IDistributionSet)['ubuntu']['warty']
2425
2526
26== Source Files ==27Source Files
28------------
2729
28An ISourcePackageRelease contains the file that make up the source30An ISourcePackageRelease contains the file that make up the source
29package for that release:31package for that release:
@@ -33,118 +35,48 @@
33 upstream source.35 upstream source.
34 * A '.dsc' package description file.36 * A '.dsc' package description file.
3537
36 >>> warty_firefox_srcpkg = warty.getSourcePackage(38 >>> warty_firefox_srcpkg = warty.getSourcePackage(
37 ... 'mozilla-firefox').currentrelease39 ... 'mozilla-firefox').currentrelease
3840
39 >>> srcfile = warty_firefox_srcpkg.files[0]41 >>> srcfile = warty_firefox_srcpkg.files[0]
4042
41 >>> verifyObject(ISourcePackageReleaseFile, srcfile)43 >>> verifyObject(ISourcePackageReleaseFile, srcfile)
42 True44 True
4345
44 >>> verifyObject(ILibraryFileAlias, srcfile.libraryfile)46 >>> verifyObject(ILibraryFileAlias, srcfile.libraryfile)
45 True47 True
4648
47 >>> srcfile.libraryfile.filename49 >>> srcfile.libraryfile.filename
48 u'firefox_0.9.2.orig.tar.gz'50 u'firefox_0.9.2.orig.tar.gz'
4951
50 >>> srcfile.libraryfile.http_url52 >>> srcfile.libraryfile.http_url
51 'http://.../3/firefox_0.9.2.orig.tar.gz'53 'http://.../3/firefox_0.9.2.orig.tar.gz'
5254
5355
54== Binary Files ==56Binary Files
57------------
5558
56An IBinaryPackageRelease contains only one file which is the59An IBinaryPackageRelease contains only one file which is the
57instalable debian-format file:60instalable debian-format file:
5861
59 * An '.deb'62 * An '.deb'
6063
61 >>> warty_i386_pmount_binpkg = warty['i386'].getBinaryPackage(64 >>> warty_i386_pmount_binpkg = warty['i386'].getBinaryPackage(
62 ... 'pmount')['2:1.9-1']65 ... 'pmount')['2:1.9-1']
6366
64 >>> warty_i386_pmount_binpkg.name67 >>> warty_i386_pmount_binpkg.name
65 u'pmount'68 u'pmount'
6669
67 >>> debfile = warty_i386_pmount_binpkg.files[0]70 >>> debfile = warty_i386_pmount_binpkg.files[0]
6871
69 >>> verifyObject(IBinaryPackageFile, debfile)72 >>> verifyObject(IBinaryPackageFile, debfile)
70 True73 True
7174
72 >>> verifyObject(ILibraryFileAlias, debfile.libraryfile)75 >>> verifyObject(ILibraryFileAlias, debfile.libraryfile)
73 True76 True
7477
75 >>> debfile.libraryfile.filename78 >>> debfile.libraryfile.filename
76 u'pmount_1.9-1_all.deb'79 u'pmount_1.9-1_all.deb'
7780
78 >>> debfile.libraryfile.http_url81 >>> debfile.libraryfile.http_url
79 'http://.../37/pmount_1.9-1_all.deb'82 'http://.../37/pmount_1.9-1_all.deb'
80
81
82== Utilities ==
83
84There is a utility class IBinaryPackageFileSet that will return
85BinaryPackageFile records.
86
87 >>> from lp.soyuz.interfaces.files import (
88 ... IBinaryPackageFileSet)
89 >>> file_set = getUtility(IBinaryPackageFileSet)
90
91It only contains one method, getByPackageUploadIDs(), that will return
92all the BinaryPackageFiles that are associated with the supplied
93PackageUpload IDs.
94
95 >>> ids = (2,)
96 >>> binary_package_files = file_set.getByPackageUploadIDs(ids)
97 >>> for binary_package_file in binary_package_files:
98 ... print binary_package_file.libraryfile.filename
99 pmount_1.0-1_all.deb
100
101Additional IDs may also be passed and if they don't have any
102BinaryPackageFiles they are ignored and don't affect the results.
103
104 >>> ids = (1,2,3,4,5)
105 >>> binary_package_files = file_set.getByPackageUploadIDs(ids)
106 >>> for binary_package_file in binary_package_files:
107 ... print binary_package_file.libraryfile.filename
108 pmount_1.0-1_all.deb
109
110If no IDs or None is passed, an empty list is returned.
111
112 >>> file_set.getByPackageUploadIDs([])
113 []
114
115 >>> file_set.getByPackageUploadIDs(None)
116 []
117
118There is also a utility called SourcePackageReleaseFileSet which has the
119same method, getByPackageUploadIDs(), and performs the same function.
120
121 >>> import operator
122 >>> from lp.soyuz.interfaces.files import (
123 ... ISourcePackageReleaseFileSet)
124 >>> source_file_set = getUtility(ISourcePackageReleaseFileSet)
125 >>> ids = (15,)
126 >>> source_files = source_file_set.getByPackageUploadIDs(ids)
127 >>> for source_file in sorted(source_files,
128 ... key=operator.attrgetter('id')):
129 ... print source_file.libraryfile.filename
130 firefox_0.9.2.orig.tar.gz
131 iceweasel-1.0.dsc
132
133As with the same method for binary files, it will ignore IDs for which
134there are no uploads:
135
136 >>> ids = (14, 15)
137 >>> source_files = source_file_set.getByPackageUploadIDs(ids)
138 >>> for source_file in sorted(source_files,
139 ... key=operator.attrgetter('id')):
140 ... print source_file.libraryfile.filename
141 firefox_0.9.2.orig.tar.gz
142 iceweasel-1.0.dsc
143
144If no IDs or None is passed, an empty list is returned.
145
146 >>> source_file_set.getByPackageUploadIDs([])
147 []
148
149 >>> source_file_set.getByPackageUploadIDs(None)
150 []
15183
=== modified file 'lib/lp/soyuz/interfaces/files.py'
--- lib/lp/soyuz/interfaces/files.py 2013-01-07 02:40:55 +0000
+++ lib/lp/soyuz/interfaces/files.py 2013-01-08 05:53:51 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009-2011 Canonical Ltd. This software is licensed under the1# Copyright 2009-2013 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Package file interfaces."""4"""Package file interfaces."""
@@ -7,9 +7,7 @@
77
8__all__ = [8__all__ = [
9 'IBinaryPackageFile',9 'IBinaryPackageFile',
10 'IBinaryPackageFileSet',
11 'ISourcePackageReleaseFile',10 'ISourcePackageReleaseFile',
12 'ISourcePackageReleaseFileSet',
13 ]11 ]
1412
15from lazr.restful.fields import Reference13from lazr.restful.fields import Reference
@@ -48,21 +46,6 @@
48 )46 )
4947
5048
51class IBinaryPackageFileSet(Interface):
52 """The set of all `BinaryPackageFile`s."""
53
54 def getByPackageUploadIDs(package_upload_ids):
55 """Return `BinaryPackageFile`s for the `PackageUpload` IDs."""
56
57 def loadLibraryFiles(binary_files):
58 """Bulk-load Librarian files associated with `binary_files`.
59
60 This loads the `LibraryFileAlias` and `LibraryFileContent` for each
61 of `binary_files` into the ORM cache, and returns an iterable of
62 `LibraryFileAlias`.
63 """
64
65
66class ISourcePackageReleaseFile(Interface):49class ISourcePackageReleaseFile(Interface):
67 """A source package release to librarian link record."""50 """A source package release to librarian link record."""
6851
@@ -93,10 +76,3 @@
93 title=_('Whether this file is an original tarball'),76 title=_('Whether this file is an original tarball'),
94 required=True, readonly=False,77 required=True, readonly=False,
95 )78 )
96
97
98class ISourcePackageReleaseFileSet(Interface):
99 """The set of all `SourcePackageRelease`s."""
100
101 def getByPackageUploadIDs(package_upload_ids):
102 """Return `SourcePackageReleaseFile`s for the `PackageUpload` IDs."""
10379
=== modified file 'lib/lp/soyuz/interfaces/queue.py'
--- lib/lp/soyuz/interfaces/queue.py 2012-12-10 06:27:12 +0000
+++ lib/lp/soyuz/interfaces/queue.py 2013-01-08 05:53:51 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009-2012 Canonical Ltd. This software is licensed under the1# Copyright 2009-2013 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Queue interfaces."""4"""Queue interfaces."""
@@ -775,9 +775,6 @@
775 def getBuildByBuildIDs(build_ids):775 def getBuildByBuildIDs(build_ids):
776 """Return `PackageUploadBuilds`s for the supplied build IDs."""776 """Return `PackageUploadBuilds`s for the supplied build IDs."""
777777
778 def getSourceBySourcePackageReleaseIDs(spr_ids):
779 """Return `PackageUploadSource`s for the sourcepackagerelease IDs."""
780
781 def getByPackageCopyJobIDs(pcj_ids):778 def getByPackageCopyJobIDs(pcj_ids):
782 """Return `PackageUpload`s using `PackageCopyJob`s.779 """Return `PackageUpload`s using `PackageCopyJob`s.
783780
784781
=== modified file 'lib/lp/soyuz/model/files.py'
--- lib/lp/soyuz/model/files.py 2013-01-07 02:40:55 +0000
+++ lib/lp/soyuz/model/files.py 2013-01-08 05:53:51 +0000
@@ -1,10 +1,9 @@
1# Copyright 2009 Canonical Ltd. This software is licensed under the1# Copyright 2009-2013 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4__metaclass__ = type4__metaclass__ = type
5__all__ = [5__all__ = [
6 'BinaryPackageFile',6 'BinaryPackageFile',
7 'BinaryPackageFileSet',
8 'SourceFileMixin',7 'SourceFileMixin',
9 'SourcePackageReleaseFile',8 'SourcePackageReleaseFile',
10 ]9 ]
@@ -13,22 +12,12 @@
13from zope.interface import implements12from zope.interface import implements
1413
15from lp.registry.interfaces.sourcepackage import SourcePackageFileType14from lp.registry.interfaces.sourcepackage import SourcePackageFileType
16from lp.services.database.bulk import load_related
17from lp.services.database.enumcol import EnumCol15from lp.services.database.enumcol import EnumCol
18from lp.services.database.sqlbase import (16from lp.services.database.sqlbase import SQLBase
19 SQLBase,
20 sqlvalues,
21 )
22from lp.services.librarian.model import (
23 LibraryFileAlias,
24 LibraryFileContent,
25 )
26from lp.soyuz.enums import BinaryPackageFileType17from lp.soyuz.enums import BinaryPackageFileType
27from lp.soyuz.interfaces.files import (18from lp.soyuz.interfaces.files import (
28 IBinaryPackageFile,19 IBinaryPackageFile,
29 IBinaryPackageFileSet,
30 ISourcePackageReleaseFile,20 ISourcePackageReleaseFile,
31 ISourcePackageReleaseFileSet,
32 )21 )
3322
3423
@@ -46,33 +35,6 @@
46 schema=BinaryPackageFileType)35 schema=BinaryPackageFileType)
4736
4837
49class BinaryPackageFileSet:
50 """See `IBinaryPackageFileSet`."""
51 implements(IBinaryPackageFileSet)
52
53 def getByPackageUploadIDs(self, package_upload_ids):
54 """See `IBinaryPackageFileSet`."""
55 if package_upload_ids is None or len(package_upload_ids) == 0:
56 return []
57 return BinaryPackageFile.select("""
58 PackageUploadBuild.packageupload = PackageUpload.id AND
59 PackageUpload.id IN %s AND
60 BinaryPackageBuild.id = PackageUploadBuild.build AND
61 BinaryPackageRelease.build = BinaryPackageBuild.id AND
62 BinaryPackageFile.binarypackagerelease = BinaryPackageRelease.id
63 """ % sqlvalues(package_upload_ids),
64 clauseTables=["PackageUpload", "PackageUploadBuild",
65 "BinaryPackageBuild", "BinaryPackageRelease"],
66 prejoins=["binarypackagerelease", "binarypackagerelease.build",
67 "binarypackagerelease.binarypackagename"])
68
69 def loadLibraryFiles(self, binary_files):
70 """See `IBinaryPackageFileSet`."""
71 lfas = load_related(LibraryFileAlias, binary_files, ['libraryfileID'])
72 load_related(LibraryFileContent, lfas, ['contentID'])
73 return lfas
74
75
76class SourceFileMixin:38class SourceFileMixin:
77 """Mix-in class for common functionality between source file classes."""39 """Mix-in class for common functionality between source file classes."""
7840
@@ -94,23 +56,3 @@
94 libraryfile = ForeignKey(foreignKey='LibraryFileAlias',56 libraryfile = ForeignKey(foreignKey='LibraryFileAlias',
95 dbName='libraryfile')57 dbName='libraryfile')
96 filetype = EnumCol(schema=SourcePackageFileType)58 filetype = EnumCol(schema=SourcePackageFileType)
97
98
99class SourcePackageReleaseFileSet:
100 """See `ISourcePackageReleaseFileSet`."""
101 implements(ISourcePackageReleaseFileSet)
102
103 def getByPackageUploadIDs(self, package_upload_ids):
104 """See `ISourcePackageReleaseFileSet`."""
105 if package_upload_ids is None or len(package_upload_ids) == 0:
106 return []
107 return SourcePackageReleaseFile.select("""
108 PackageUploadSource.packageupload = PackageUpload.id AND
109 PackageUpload.id IN %s AND
110 SourcePackageReleaseFile.sourcepackagerelease =
111 PackageUploadSource.sourcepackagerelease
112 """ % sqlvalues(package_upload_ids),
113 clauseTables=["PackageUpload", "PackageUploadSource"],
114 prejoins=["libraryfile", "libraryfile.content",
115 "sourcepackagerelease",
116 "sourcepackagerelease.sourcepackagename"])
11759
=== modified file 'lib/lp/soyuz/model/queue.py'
--- lib/lp/soyuz/model/queue.py 2013-01-02 22:59:10 +0000
+++ lib/lp/soyuz/model/queue.py 2013-01-08 05:53:51 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009-2012 Canonical Ltd. This software is licensed under the1# Copyright 2009-2013 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4__metaclass__ = type4__metaclass__ = type
@@ -48,6 +48,7 @@
48from lp.archivepublisher.customupload import CustomUploadError48from lp.archivepublisher.customupload import CustomUploadError
49from lp.archivepublisher.debversion import Version49from lp.archivepublisher.debversion import Version
50from lp.archiveuploader.tagfiles import parse_tagfile_content50from lp.archiveuploader.tagfiles import parse_tagfile_content
51from lp.buildmaster.model.packagebuild import PackageBuild
51from lp.registry.interfaces.pocket import PackagePublishingPocket52from lp.registry.interfaces.pocket import PackagePublishingPocket
52from lp.registry.model.sourcepackagename import SourcePackageName53from lp.registry.model.sourcepackagename import SourcePackageName
53from lp.services.auditor.client import AuditorClient54from lp.services.auditor.client import AuditorClient
@@ -75,7 +76,10 @@
75from lp.services.features import getFeatureFlag76from lp.services.features import getFeatureFlag
76from lp.services.librarian.browser import ProxiedLibraryFileAlias77from lp.services.librarian.browser import ProxiedLibraryFileAlias
77from lp.services.librarian.interfaces.client import DownloadFailed78from lp.services.librarian.interfaces.client import DownloadFailed
78from lp.services.librarian.model import LibraryFileAlias79from lp.services.librarian.model import (
80 LibraryFileAlias,
81 LibraryFileContent,
82 )
79from lp.services.librarian.utils import copy_and_close83from lp.services.librarian.utils import copy_and_close
80from lp.services.mail.signedmessage import strip_pgp_signature84from lp.services.mail.signedmessage import strip_pgp_signature
81from lp.services.propertycache import (85from lp.services.propertycache import (
@@ -96,6 +100,7 @@
96from lp.soyuz.interfaces.archivepermission import IArchivePermissionSet100from lp.soyuz.interfaces.archivepermission import IArchivePermissionSet
97from lp.soyuz.interfaces.component import IComponentSet101from lp.soyuz.interfaces.component import IComponentSet
98from lp.soyuz.interfaces.packagecopyjob import IPackageCopyJobSource102from lp.soyuz.interfaces.packagecopyjob import IPackageCopyJobSource
103from lp.soyuz.interfaces.packagediff import IPackageDiffSet
99from lp.soyuz.interfaces.publishing import (104from lp.soyuz.interfaces.publishing import (
100 IPublishingSet,105 IPublishingSet,
101 name_priority_map,106 name_priority_map,
@@ -115,7 +120,11 @@
115 QueueStateWriteProtectedError,120 QueueStateWriteProtectedError,
116 )121 )
117from lp.soyuz.interfaces.section import ISectionSet122from lp.soyuz.interfaces.section import ISectionSet
123from lp.soyuz.model.binarypackagename import BinaryPackageName
124from lp.soyuz.model.binarypackagerelease import BinaryPackageRelease
125from lp.soyuz.model.component import Component
118from lp.soyuz.model.distroarchseries import DistroArchSeries126from lp.soyuz.model.distroarchseries import DistroArchSeries
127from lp.soyuz.model.section import Section
119from lp.soyuz.pas import BuildDaemonPackagesArchSpecific128from lp.soyuz.pas import BuildDaemonPackagesArchSpecific
120129
121# There are imports below in PackageUploadCustom for various bits130# There are imports below in PackageUploadCustom for various bits
@@ -1683,17 +1692,8 @@
1683 """See `IPackageUploadSet`."""1692 """See `IPackageUploadSet`."""
1684 if build_ids is None or len(build_ids) == 0:1693 if build_ids is None or len(build_ids) == 0:
1685 return []1694 return []
1686 return PackageUploadBuild.select("""1695 return PackageUploadBuild.select(
1687 PackageUploadBuild.build IN %s1696 "PackageUploadBuild.build IN %s" % sqlvalues(build_ids))
1688 """ % sqlvalues(build_ids))
1689
1690 def getSourceBySourcePackageReleaseIDs(self, spr_ids):
1691 """See `IPackageUploadSet`."""
1692 if spr_ids is None or len(spr_ids) == 0:
1693 return []
1694 return PackageUploadSource.select("""
1695 PackageUploadSource.sourcepackagerelease IN %s
1696 """ % sqlvalues(spr_ids))
16971697
1698 def getByPackageCopyJobIDs(self, pcj_ids):1698 def getByPackageCopyJobIDs(self, pcj_ids):
1699 """See `IPackageUploadSet`."""1699 """See `IPackageUploadSet`."""
@@ -1728,18 +1728,32 @@
1728 source_sprs = load_related(1728 source_sprs = load_related(
1729 SourcePackageRelease, puses, ['sourcepackagereleaseID'])1729 SourcePackageRelease, puses, ['sourcepackagereleaseID'])
1730 bpbs = load_related(BinaryPackageBuild, pubs, ['buildID'])1730 bpbs = load_related(BinaryPackageBuild, pubs, ['buildID'])
1731 load_related(PackageBuild, bpbs, ['package_build_id'])
1731 load_related(DistroArchSeries, bpbs, ['distro_arch_series_id'])1732 load_related(DistroArchSeries, bpbs, ['distro_arch_series_id'])
1732 binary_sprs = load_related(1733 binary_sprs = load_related(
1733 SourcePackageRelease, bpbs, ['source_package_release_id'])1734 SourcePackageRelease, bpbs, ['source_package_release_id'])
1735 bprs = load_referencing(BinaryPackageRelease, bpbs, ['buildID'])
1736 load_related(BinaryPackageName, bprs, ['binarypackagenameID'])
1734 sprs = source_sprs + binary_sprs1737 sprs = source_sprs + binary_sprs
17351738
1736 load_related(SourcePackageName, sprs, ['sourcepackagenameID'])1739 load_related(SourcePackageName, sprs, ['sourcepackagenameID'])
1740 load_related(Section, sprs + bprs, ['sectionID'])
1741 load_related(Component, sprs, ['componentID'])
1737 load_related(LibraryFileAlias, uploads, ['changes_file_id'])1742 load_related(LibraryFileAlias, uploads, ['changes_file_id'])
1738 publications = load_referencing(1743 publications = load_referencing(
1739 SourcePackagePublishingHistory, sprs, ['sourcepackagereleaseID'])1744 SourcePackagePublishingHistory, sprs, ['sourcepackagereleaseID'])
1740 load_related(Archive, publications, ['archiveID'])1745 load_related(Archive, publications, ['archiveID'])
1746 diffs = getUtility(IPackageDiffSet).getDiffsToReleases(
1747 sprs, preload_for_display=True)
1748
1749 puc_lfas = load_related(LibraryFileAlias, pucs, ['libraryfilealiasID'])
1750 load_related(LibraryFileContent, puc_lfas, ['contentID'])
1751
1741 for spr_cache in sprs:1752 for spr_cache in sprs:
1742 get_property_cache(spr_cache).published_archives = []1753 get_property_cache(spr_cache).published_archives = []
1754 get_property_cache(spr_cache).package_diffs = []
1743 for publication in publications:1755 for publication in publications:
1744 spr_cache = get_property_cache(publication.sourcepackagerelease)1756 spr_cache = get_property_cache(publication.sourcepackagerelease)
1745 spr_cache.published_archives.append(publication.archive)1757 spr_cache.published_archives.append(publication.archive)
1758 for diff in diffs:
1759 get_property_cache(diff.to_source).package_diffs.append(diff)
17461760
=== modified file 'lib/lp/soyuz/model/sourcepackagerelease.py'
--- lib/lp/soyuz/model/sourcepackagerelease.py 2013-01-02 22:59:10 +0000
+++ lib/lp/soyuz/model/sourcepackagerelease.py 2013-01-08 05:53:51 +0000
@@ -30,6 +30,7 @@
30from storm.info import ClassAlias30from storm.info import ClassAlias
31from storm.locals import (31from storm.locals import (
32 Int,32 Int,
33 Desc,
33 Reference,34 Reference,
34 )35 )
35from storm.store import Store36from storm.store import Store
@@ -59,7 +60,10 @@
59 LibraryFileAlias,60 LibraryFileAlias,
60 LibraryFileContent,61 LibraryFileContent,
61 )62 )
62from lp.services.propertycache import cachedproperty63from lp.services.propertycache import (
64 cachedproperty,
65 get_property_cache,
66 )
63from lp.soyuz.enums import PackageDiffStatus67from lp.soyuz.enums import PackageDiffStatus
64from lp.soyuz.interfaces.archive import MAIN_ARCHIVE_PURPOSES68from lp.soyuz.interfaces.archive import MAIN_ARCHIVE_PURPOSES
65from lp.soyuz.interfaces.binarypackagebuild import IBinaryPackageBuildSet69from lp.soyuz.interfaces.binarypackagebuild import IBinaryPackageBuildSet
@@ -165,8 +169,6 @@
165 joinColumn='sourcepackagerelease', orderBy="libraryfile")169 joinColumn='sourcepackagerelease', orderBy="libraryfile")
166 publishings = SQLMultipleJoin('SourcePackagePublishingHistory',170 publishings = SQLMultipleJoin('SourcePackagePublishingHistory',
167 joinColumn='sourcepackagerelease', orderBy="-datecreated")171 joinColumn='sourcepackagerelease', orderBy="-datecreated")
168 package_diffs = SQLMultipleJoin(
169 'PackageDiff', joinColumn='to_source', orderBy="-date_requested")
170172
171 _user_defined_fields = StringCol(dbName='user_defined_fields')173 _user_defined_fields = StringCol(dbName='user_defined_fields')
172174
@@ -209,6 +211,12 @@
209 return []211 return []
210 return simplejson.loads(self._user_defined_fields)212 return simplejson.loads(self._user_defined_fields)
211213
214 @cachedproperty
215 def package_diffs(self):
216 return list(Store.of(self).find(
217 PackageDiff, to_source=self).order_by(
218 Desc(PackageDiff.date_requested)))
219
212 @property220 @property
213 def builds(self):221 def builds(self):
214 """See `ISourcePackageRelease`."""222 """See `ISourcePackageRelease`."""
@@ -584,6 +592,8 @@
584 else:592 else:
585 status = PackageDiffStatus.PENDING593 status = PackageDiffStatus.PENDING
586594
595 Store.of(to_sourcepackagerelease).flush()
596 del get_property_cache(to_sourcepackagerelease).package_diffs
587 return PackageDiff(597 return PackageDiff(
588 from_source=self, to_source=to_sourcepackagerelease,598 from_source=self, to_source=to_sourcepackagerelease,
589 requester=requester, status=status)599 requester=requester, status=status)
590600
=== removed file 'lib/lp/soyuz/tests/test_binarypackagefile.py'
--- lib/lp/soyuz/tests/test_binarypackagefile.py 2012-01-01 02:58:52 +0000
+++ lib/lp/soyuz/tests/test_binarypackagefile.py 1970-01-01 00:00:00 +0000
@@ -1,26 +0,0 @@
1# Copyright 2011 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4"""Unit tests for `IBinaryPackageFile` and `IBinaryPackageFileSet`."""
5
6__metaclass__ = type
7
8from zope.component import getUtility
9
10from lp.soyuz.interfaces.files import IBinaryPackageFileSet
11from lp.testing import TestCaseWithFactory
12from lp.testing.layers import LaunchpadZopelessLayer
13from lp.testing.matchers import Provides
14
15
16class TestBinaryPackageFileSet(TestCaseWithFactory):
17 layer = LaunchpadZopelessLayer
18
19 def test_implements_interface(self):
20 file_set = getUtility(IBinaryPackageFileSet)
21 self.assertThat(file_set, Provides(IBinaryPackageFileSet))
22
23 def test_loadLibraryFiles_returns_associated_lfas(self):
24 bpf = self.factory.makeBinaryPackageFile()
25 lfas = getUtility(IBinaryPackageFileSet).loadLibraryFiles([bpf])
26 self.assertContentEqual([bpf.libraryfile], lfas)
270
=== modified file 'lib/lp/soyuz/tests/test_packageupload.py'
--- lib/lp/soyuz/tests/test_packageupload.py 2013-01-02 06:26:34 +0000
+++ lib/lp/soyuz/tests/test_packageupload.py 2013-01-08 05:53:51 +0000
@@ -1,4 +1,4 @@
1# Copyright 2009-2012 Canonical Ltd. This software is licensed under the1# Copyright 2009-2013 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Test Build features."""4"""Test Build features."""
@@ -1304,4 +1304,4 @@
1304 IStore(uploads[0].__class__).invalidate()1304 IStore(uploads[0].__class__).invalidate()
1305 with StormStatementRecorder() as recorder:1305 with StormStatementRecorder() as recorder:
1306 ws_distroseries.getPackageUploads()1306 ws_distroseries.getPackageUploads()
1307 self.assertThat(recorder, HasQueryCount(Equals(27)))1307 self.assertThat(recorder, HasQueryCount(Equals(33)))