Merge lp:~stevenk/launchpad/fixes-bug-553068 into lp:launchpad

Proposed by Steve Kowalik
Status: Merged
Approved by: Gavin Panella
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~stevenk/launchpad/fixes-bug-553068
Merge into: lp:launchpad
Diff against target: 117 lines (+22/-11)
2 files modified
lib/lp/soyuz/doc/archive.txt (+18/-7)
lib/lp/soyuz/model/archive.py (+4/-4)
To merge this branch: bzr merge lp:~stevenk/launchpad/fixes-bug-553068
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve
Review via email: mp+22926@code.launchpad.net

Commit message

Slightly refactor findDepCandidateByName to deal with multiple archive dependencies.

Description of the change

This branch fixes bug 553068 by allowing findDepCandidateByName to deal with multiple archive dependencies.

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) wrote :

Hi Steven,

This looks good! I have some ideas for making findDepCandidateByName()
faster, but it's good as is.

Gavin.

> === modified file 'lib/lp/soyuz/model/archive.py'
> --- lib/lp/soyuz/model/archive.py 2010-03-18 09:11:33 +0000
> +++ lib/lp/soyuz/model/archive.py 2010-04-07 11:03:27 +0000
> @@ -779,10 +779,8 @@
> if self.is_ppa:
> archives.append(self.distribution.main_archive.id)
> archives.append(self.id)
> - dep = ArchiveDependency.selectOneBy(archive=self)
> - while dep is not None:
> - archives.append(dep.dependency.id)
> - dep = ArchiveDependency.selectOneBy(archive=dep.dependency)
> + archives.extend(
> + [archive_dep.dependency.id for archive_dep in self.dependencies])

I've got a couple of ways to make this more efficient.

First, the list comprehension can be dropped, and dependencyID can be
used instead of loading the dependency Archive (which may result in
another database query). The diff for that is:

{{{
=== modified file 'lib/lp/soyuz/model/archive.py'
--- lib/lp/soyuz/model/archive.py 2010-04-07 06:59:54 +0000
+++ lib/lp/soyuz/model/archive.py 2010-04-07 11:16:29 +0000
@@ -780,7 +780,7 @@
             archives.append(self.distribution.main_archive.id)
         archives.append(self.id)
         archives.extend(
- [archive_dep.dependency.id for archive_dep in self.dependencies])
+ archive_dep.dependencyID for archive_dep in self.dependencies)

         query = """
             binarypackagename = %s AND

}}}

This can be taken even further! Though the above is perfectly okay, we
can avoid loading even the ArchiveDependency objects:

{{{
=== modified file 'lib/lp/soyuz/model/archive.py'
--- lib/lp/soyuz/model/archive.py 2010-04-07 06:59:54 +0000
+++ lib/lp/soyuz/model/archive.py 2010-04-07 11:19:32 +0000
@@ -18,6 +18,7 @@
 from storm.expr import Or, And, Select
 from storm.locals import Count, Join
 from storm.store import Store
+from storm.zope.interfaces import IResultSet
 from zope.component import getUtility
 from zope.event import notify
 from zope.interface import alsoProvides, implements
@@ -780,7 +781,9 @@
             archives.append(self.distribution.main_archive.id)
         archives.append(self.id)
         archives.extend(
- [archive_dep.dependency.id for archive_dep in self.dependencies])
+ IResultSet(self.dependencies).values(
+ ArchiveDependency.dependencyID))
+

         query = """
             binarypackagename = %s AND

}}}

review: Approve
Revision history for this message
Gavin Panella (allenap) wrote :

Also, let me know if you need someone to land this branch; I'm happy to do it.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/soyuz/doc/archive.txt'
2--- lib/lp/soyuz/doc/archive.txt 2010-03-23 22:15:02 +0000
3+++ lib/lp/soyuz/doc/archive.txt 2010-04-08 02:42:27 +0000
4@@ -1317,6 +1317,14 @@
5 package is not published on the context PPA but is available somewhere
6 in the archive dependency domain it will be found.
7
8+We also add another archive dependency here to exercise findDepCandidateByName
9+a little more.
10+
11+ >>> joe = factory.makePerson(email='joe@example.com')
12+ >>> second_ppa = factory.makeArchive(name="secondppa", owner=joe)
13+ >>> second_archive_dep = cprov.archive.addArchiveDependency(
14+ ... second_ppa, release_pocket, main_component)
15+
16 'at' binary package is not present in Celso's PPA.
17
18 >>> cprov_archive.getAllPublishedBinaries(name='at').count()
19@@ -1339,6 +1347,9 @@
20 >>> primary_candidate == ppa_candidate
21 True
22
23+And clean-up after ourselves:
24+
25+ >>> ignore = cprov.archive.removeArchiveDependency(second_ppa)
26
27 == Creating a package copy request from an IArchive ==
28
29@@ -1347,7 +1358,7 @@
30
31 >>> requestor = factory.makePerson(name='me-copy')
32 >>> copy_target = factory.makeCopyArchiveLocation(
33- ... distribution=ubuntu, name='my-copy-archive')
34+ ... distribution=ubuntu, name='my-copy-archive', owner=requestor)
35 >>> pcr = ubuntu.main_archive.requestPackageCopy(copy_target, requestor)
36 >>> print pcr
37 Package copy request
38@@ -1518,7 +1529,7 @@
39
40 >>> archive_purposes = [archive.purpose.name for archive in archive_set]
41 >>> len(archive_purposes)
42- 18
43+ 20
44
45 >>> print sorted(set(archive_purposes))
46 ['COPY', 'DEBUG', 'PARTNER', 'PPA', 'PRIMARY']
47@@ -1919,7 +1930,7 @@
48 ... ubuntu, purposes=ArchivePurpose.COPY)
49 >>> print_archive_names(ubuntu_copy_archives)
50 Name Owner Private Enabled
51- my-copy-archive person-name6 False True
52+ my-copy-archive me-copy False True
53
54 The method `getArchivesForDistribution` can also be used with multiple
55 purposes. First we'll check how many partner archives are in the DB:
56@@ -1937,7 +1948,7 @@
57 ... ubuntu, purposes=[ArchivePurpose.COPY, ArchivePurpose.PARTNER])
58 >>> print_archive_names(copy_n_partner_archives)
59 Name Owner Private Enabled
60- my-copy-archive person-name6 False True
61+ my-copy-archive me-copy False True
62 partner ubuntu-team False True
63
64 First we create four copy archives for ubuntu:
65@@ -1969,7 +1980,7 @@
66 >>> print_archive_names(ubuntu_copy_archives)
67 Name Owner Private Enabled
68 fine-copy copy-owner2 False True
69- my-copy-archive person-name6 False True
70+ my-copy-archive me-copy False True
71 team-archive t1 False True
72 ultimate-copy copy-owner1 False True
73
74@@ -2020,7 +2031,7 @@
75 >>> print_archive_names(ubuntu_copy_archives)
76 Name Owner Private Enabled
77 fine-copy copy-owner2 False True
78- my-copy-archive person-name6 True True
79+ my-copy-archive me-copy True True
80 ultimate-copy copy-owner1 False True
81
82 An admin will see all the private and disabled archives in the results:
83@@ -2031,7 +2042,7 @@
84 >>> print_archive_names(ubuntu_copy_archives)
85 Name Owner Private Enabled
86 fine-copy copy-owner2 False True
87- my-copy-archive person-name6 True True
88+ my-copy-archive me-copy True True
89 team-archive t1 True True
90 there-we-go juergen False False
91 true-copy copy-owner2 False False
92
93=== modified file 'lib/lp/soyuz/model/archive.py'
94--- lib/lp/soyuz/model/archive.py 2010-03-23 22:15:02 +0000
95+++ lib/lp/soyuz/model/archive.py 2010-04-08 02:42:27 +0000
96@@ -18,6 +18,7 @@
97 from storm.expr import Or, And, Select, Sum
98 from storm.locals import Count, Join
99 from storm.store import Store
100+from storm.zope.interfaces import IResultSet
101 from zope.component import getUtility
102 from zope.event import notify
103 from zope.interface import alsoProvides, implements
104@@ -784,10 +785,9 @@
105 if self.is_ppa:
106 archives.append(self.distribution.main_archive.id)
107 archives.append(self.id)
108- dep = ArchiveDependency.selectOneBy(archive=self)
109- while dep is not None:
110- archives.append(dep.dependency.id)
111- dep = ArchiveDependency.selectOneBy(archive=dep.dependency)
112+ archives.extend(
113+ IResultSet(self.dependencies).values(
114+ ArchiveDependency.dependencyID))
115
116 query = """
117 binarypackagename = %s AND