Merge lp:~stevenk/launchpad/calculateOldBinaries-use-denorm into lp:launchpad

Proposed by Steve Kowalik on 2012-01-17
Status: Merged
Approved by: William Grant on 2012-01-17
Approved revision: no longer in the source branch.
Merged at revision: 14682
Proposed branch: lp:~stevenk/launchpad/calculateOldBinaries-use-denorm
Merge into: lp:launchpad
Diff against target: 91 lines (+23/-28)
1 file modified
lib/lp/soyuz/model/binarypackagename.py (+23/-28)
To merge this branch: bzr merge lp:~stevenk/launchpad/calculateOldBinaries-use-denorm
Reviewer Review Type Date Requested Status
William Grant code 2012-01-17 Approve on 2012-01-17
Review via email: mp+88816@code.launchpad.net

Commit Message

[r=wgrant][bug=909240] Rewrite the query in IBinaryPackageNameSet.getNotNewByName() to use the denorm'd BPN.

Description of the Change

Rewrite the query in IBinaryPackageNameSet.getNotNewByName() to use IStore, and to no longer join against BinaryPackageRelease, and instead use the denormalised data that is directly in BinaryPackagePublishingHistory.

I also removed a stupid duplication effort in terms of the statuses that it checks, and removed a large amount of pointless comments.

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
1=== modified file 'lib/lp/soyuz/model/binarypackagename.py'
2--- lib/lp/soyuz/model/binarypackagename.py 2011-12-30 06:14:56 +0000
3+++ lib/lp/soyuz/model/binarypackagename.py 2012-01-17 08:51:25 +0000
4@@ -1,4 +1,4 @@
5-# Copyright 2009 Canonical Ltd. This software is licensed under the
6+# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
7 # GNU Affero General Public License version 3 (see the file LICENSE).
8
9 # pylint: disable-msg=E0611,W0212
10@@ -11,13 +11,12 @@
11 'getBinaryPackageDescriptions',
12 ]
13
14-# SQLObject/SQLBase
15 from sqlobject import (
16 SQLObjectNotFound,
17 StringCol,
18 )
19 from storm.store import EmptyResultSet
20-# Zope imports
21+from storm.expr import Join
22 from zope.interface import implements
23 from zope.schema.vocabulary import SimpleTerm
24
25@@ -32,11 +31,11 @@
26 BatchedCountableIterator,
27 NamedSQLObjectHugeVocabulary,
28 )
29-from lp.soyuz.enums import PackagePublishingStatus
30 from lp.soyuz.interfaces.binarypackagename import (
31 IBinaryPackageName,
32 IBinaryPackageNameSet,
33 )
34+from lp.soyuz.interfaces.publishing import active_publishing_status
35 from lp.soyuz.model.binarypackagerelease import BinaryPackageRelease
36
37
38@@ -97,33 +96,29 @@
39
40 def getNotNewByNames(self, name_ids, distroseries, archive_ids):
41 """See `IBinaryPackageNameSet`."""
42- # Here we're returning `BinaryPackageName`s where the records
43- # for the supplied `BinaryPackageName` IDs are published in the
44- # supplied distroseries. If they're already published then they
45- # must not be new.
46+ # Circular imports.
47+ from lp.soyuz.model.distroarchseries import DistroArchSeries
48+ from lp.soyuz.model.publishing import BinaryPackagePublishingHistory
49+
50 if len(name_ids) == 0:
51 return EmptyResultSet()
52
53- statuses = (
54- PackagePublishingStatus.PUBLISHED,
55- PackagePublishingStatus.PENDING,
56- )
57-
58- return BinaryPackageName.select("""
59- BinaryPackagePublishingHistory.binarypackagerelease =
60- BinaryPackageRelease.id AND
61- BinaryPackagePublishingHistory.distroarchseries =
62- DistroArchSeries.id AND
63- DistroArchSeries.distroseries = %s AND
64- BinaryPackagePublishingHistory.status IN %s AND
65- BinaryPackagePublishingHistory.archive IN %s AND
66- BinaryPackageRelease.binarypackagename = BinaryPackageName.id AND
67- BinaryPackageName.id IN %s
68- """ % sqlvalues(distroseries, statuses, archive_ids, name_ids),
69- distinct=True,
70- clauseTables=["BinaryPackagePublishingHistory",
71- "BinaryPackageRelease",
72- "DistroArchSeries"])
73+ return IStore(BinaryPackagePublishingHistory).using(
74+ BinaryPackagePublishingHistory,
75+ Join(BinaryPackageName,
76+ BinaryPackagePublishingHistory.binarypackagenameID ==
77+ BinaryPackageName.id),
78+ Join(DistroArchSeries,
79+ BinaryPackagePublishingHistory.distroarchseriesID ==
80+ DistroArchSeries.id)
81+ ).find(
82+ BinaryPackageName,
83+ DistroArchSeries.distroseries == distroseries,
84+ BinaryPackagePublishingHistory.status.is_in(
85+ active_publishing_status),
86+ BinaryPackagePublishingHistory.archiveID.is_in(archive_ids),
87+ BinaryPackagePublishingHistory.binarypackagenameID.is_in(
88+ name_ids)).config(distinct=True)
89
90
91 class BinaryPackageNameIterator(BatchedCountableIterator):