Merge lp:~cjwatson/launchpad/recipe-vocab-many-ppas-timeout into lp:launchpad

Proposed by Colin Watson on 2018-06-27
Status: Merged
Merged at revision: 18705
Proposed branch: lp:~cjwatson/launchpad/recipe-vocab-many-ppas-timeout
Merge into: lp:launchpad
Diff against target: 159 lines (+64/-22)
4 files modified
lib/lp/code/vocabularies/sourcepackagerecipe.py (+3/-3)
lib/lp/soyuz/doc/archive.txt (+16/-0)
lib/lp/soyuz/interfaces/archive.py (+3/-0)
lib/lp/soyuz/model/archive.py (+42/-19)
To merge this branch: bzr merge lp:~cjwatson/launchpad/recipe-vocab-many-ppas-timeout
Reviewer Review Type Date Requested Status
William Grant code 2018-06-27 Approve on 2018-06-27
Review via email: mp+348569@code.launchpad.net

Commit message

Optimise BuildableDistroSeries.findSeries.

Description of the change

I'm not sure whether this will be all of it or whether target_ppas_vocabulary will need some work too, but it's a start.

To post a comment you must log in.
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/code/vocabularies/sourcepackagerecipe.py'
--- lib/lp/code/vocabularies/sourcepackagerecipe.py 2015-07-08 16:05:11 +0000
+++ lib/lp/code/vocabularies/sourcepackagerecipe.py 2018-06-27 01:01:06 +0000
@@ -1,4 +1,4 @@
1# Copyright 2010-2013 Canonical Ltd. This software is licensed under the1# Copyright 2010-2018 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"""Source Package Recipe vocabularies used in the lp/code modules."""4"""Source Package Recipe vocabularies used in the lp/code modules."""
@@ -37,8 +37,8 @@
3737
38 @classmethod38 @classmethod
39 def findSeries(self, user):39 def findSeries(self, user):
40 ppas = getUtility(IArchiveSet).getPPAsForUser(user)40 supported_distros = set(
41 supported_distros = set([ppa.distribution for ppa in ppas])41 getUtility(IArchiveSet).getPPADistributionsForUser(user))
42 # Now add in Ubuntu.42 # Now add in Ubuntu.
43 supported_distros.add(getUtility(ILaunchpadCelebrities).ubuntu)43 supported_distros.add(getUtility(ILaunchpadCelebrities).ubuntu)
44 all_series = getUtility(IDistroSeriesSet).search()44 all_series = getUtility(IDistroSeriesSet).search()
4545
=== modified file 'lib/lp/soyuz/doc/archive.txt'
--- lib/lp/soyuz/doc/archive.txt 2018-05-27 18:32:33 +0000
+++ lib/lp/soyuz/doc/archive.txt 2018-06-27 01:01:06 +0000
@@ -1208,6 +1208,22 @@
1208 >>> jblack_ppas.count()1208 >>> jblack_ppas.count()
1209 01209 0
12101210
1211'getPPADistributionsForUser' returns the distinct distributions for all the
1212PPAs that a given user participates in.
1213
1214 >>> for distribution in archive_set.getPPADistributionsForUser(cprov):
1215 ... print(distribution.display_name)
1216 Ubuntu
1217 >>> for distribution in archive_set.getPPADistributionsForUser(no_priv):
1218 ... print(distribution.display_name)
1219 Ubuntu
1220 >>> for distribution in archive_set.getPPADistributionsForUser(
1221 ... indirect_uploader):
1222 ... print(distribution.display_name)
1223 Ubuntu
1224 >>> for distribution in archive_set.getPPADistributionsForUser(jblack):
1225 ... print(distribution.display_name)
1226
1211The method getPrivatePPAs() will return a result set of all PPAs that are1227The method getPrivatePPAs() will return a result set of all PPAs that are
1212private.1228private.
12131229
12141230
=== modified file 'lib/lp/soyuz/interfaces/archive.py'
--- lib/lp/soyuz/interfaces/archive.py 2018-05-04 21:59:32 +0000
+++ lib/lp/soyuz/interfaces/archive.py 2018-06-27 01:01:06 +0000
@@ -2383,6 +2383,9 @@
2383 The result is ordered by PPA displayname.2383 The result is ordered by PPA displayname.
2384 """2384 """
23852385
2386 def getPPADistributionsForUser(user):
2387 """Return the `Distribution`s of all PPAs for the given user."""
2388
2386 def getPPAsPendingSigningKey():2389 def getPPAsPendingSigningKey():
2387 """Return all PPAs pending signing key generation.2390 """Return all PPAs pending signing key generation.
23882391
23892392
=== modified file 'lib/lp/soyuz/model/archive.py'
--- lib/lp/soyuz/model/archive.py 2018-05-04 21:59:32 +0000
+++ lib/lp/soyuz/model/archive.py 2018-06-27 01:01:06 +0000
@@ -33,6 +33,7 @@
33 Or,33 Or,
34 Select,34 Select,
35 Sum,35 Sum,
36 Union,
36 )37 )
37from storm.properties import (38from storm.properties import (
38 Int,39 Int,
@@ -40,7 +41,10 @@
40 Unicode,41 Unicode,
41 )42 )
42from storm.references import Reference43from storm.references import Reference
43from storm.store import Store44from storm.store import (
45 EmptyResultSet,
46 Store,
47 )
44from zope.component import (48from zope.component import (
45 getAdapter,49 getAdapter,
46 getUtility,50 getUtility,
@@ -2747,29 +2751,35 @@
2747 SourcePackagePublishingHistory.archive == Archive.id)2751 SourcePackagePublishingHistory.archive == Archive.id)
2748 return store.find(Archive, *clause).order_by(Archive.id).first()2752 return store.find(Archive, *clause).order_by(Archive.id).first()
27492753
2754 def _getPPAsForUserClause(self, user):
2755 """Base clause for getPPAsForUser and getPPADistributionsForUser."""
2756 direct_membership = Select(
2757 Archive.id,
2758 where=And(
2759 Archive._enabled == True,
2760 Archive.purpose == ArchivePurpose.PPA,
2761 TeamParticipation.team == Archive.ownerID,
2762 TeamParticipation.person == user,
2763 ))
2764 third_party_upload_acl = Select(
2765 Archive.id,
2766 where=And(
2767 Archive.purpose == ArchivePurpose.PPA,
2768 ArchivePermission.archiveID == Archive.id,
2769 TeamParticipation.person == user,
2770 TeamParticipation.team == ArchivePermission.personID,
2771 ))
2772 return Archive.id.is_in(
2773 Union(direct_membership, third_party_upload_acl))
2774
2750 def getPPAsForUser(self, user):2775 def getPPAsForUser(self, user):
2751 """See `IArchiveSet`."""2776 """See `IArchiveSet`."""
2752 from lp.registry.model.person import Person2777 from lp.registry.model.person import Person
2753 # If there's no user logged in, then there's no archives.2778 # If there's no user logged in, then there are no archives.
2754 if user is None:2779 if user is None:
2755 return []2780 return EmptyResultSet()
2756 store = Store.of(user)2781 store = Store.of(user)
2757 direct_membership = store.find(2782 result = store.find(Archive, self._getPPAsForUserClause(user))
2758 Archive,
2759 Archive._enabled == True,
2760 Archive.purpose == ArchivePurpose.PPA,
2761 TeamParticipation.team == Archive.ownerID,
2762 TeamParticipation.person == user,
2763 )
2764 third_party_upload_acl = store.find(
2765 Archive,
2766 Archive.purpose == ArchivePurpose.PPA,
2767 ArchivePermission.archiveID == Archive.id,
2768 TeamParticipation.person == user,
2769 TeamParticipation.team == ArchivePermission.personID,
2770 )
2771
2772 result = direct_membership.union(third_party_upload_acl)
2773 result.order_by(Archive.displayname)2783 result.order_by(Archive.displayname)
27742784
2775 def preload_owners(rows):2785 def preload_owners(rows):
@@ -2777,6 +2787,19 @@
27772787
2778 return DecoratedResultSet(result, pre_iter_hook=preload_owners)2788 return DecoratedResultSet(result, pre_iter_hook=preload_owners)
27792789
2790 def getPPADistributionsForUser(self, user):
2791 """See `IArchiveSet`."""
2792 from lp.registry.model.distribution import Distribution
2793 # If there's no user logged in, then there are no archives.
2794 if user is None:
2795 return EmptyResultSet()
2796 store = Store.of(user)
2797 result = store.find(
2798 Distribution,
2799 Distribution.id == Archive.distributionID,
2800 self._getPPAsForUserClause(user))
2801 return result.config(distinct=True)
2802
2780 def getPPAsPendingSigningKey(self):2803 def getPPAsPendingSigningKey(self):
2781 """See `IArchiveSet`."""2804 """See `IArchiveSet`."""
2782 origin = (2805 origin = (