~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/model/distroseriessourcepackagerelease.py

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-05-20 18:14:45 UTC
  • mfrom: (13048.2.8 bug-739065-2)
  • Revision ID: launchpad@pqm.canonical.com-20110520181445-atmlrkfqt66mtj7b
[r=bac][bug=739065] pre-join BinaryPackageName in the SQL query in
        DistroSeriesSourcePackageRelease.binaries;
        pre-join DistroSeriesPackageCache in the SQL query in
        DistributionSourcePackageRelease.sample_binary_packages

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
    ]
13
13
 
14
14
from lazr.delegates import delegates
 
15
from operator import itemgetter
 
16
from storm.expr import (
 
17
    And,
 
18
    Desc,
 
19
    Join,
 
20
    )
 
21
from storm.store import Store
15
22
from zope.interface import implements
16
23
from zope.security.proxy import removeSecurityProxy
17
24
 
18
25
from canonical.database.sqlbase import sqlvalues
 
26
from canonical.launchpad.components.decoratedresultset import (
 
27
    DecoratedResultSet,
 
28
    )
19
29
from lp.registry.interfaces.distroseries import IDistroSeries
20
30
from lp.soyuz.enums import PackagePublishingStatus
21
31
from lp.soyuz.interfaces.distroseriessourcepackagerelease import (
22
32
    IDistroSeriesSourcePackageRelease,
23
33
    )
24
34
from lp.soyuz.interfaces.sourcepackagerelease import ISourcePackageRelease
 
35
from lp.soyuz.model.binarypackagebuild import BinaryPackageBuild
 
36
from lp.soyuz.model.binarypackagename import BinaryPackageName
25
37
from lp.soyuz.model.binarypackagerelease import BinaryPackageRelease
26
 
from lp.soyuz.model.publishing import SourcePackagePublishingHistory
 
38
from lp.soyuz.model.publishing import (
 
39
    BinaryPackagePublishingHistory,
 
40
    SourcePackagePublishingHistory,
 
41
    )
27
42
 
28
43
 
29
44
class DistroSeriesSourcePackageRelease:
112
127
 
113
128
        return (
114
129
            [build for build in distro_builds
115
 
                if build.distro_arch_series.distroseries == self.distroseries])
 
130
             if build.distro_arch_series.distroseries == self.distroseries])
116
131
 
117
132
    @property
118
133
    def files(self):
122
137
    @property
123
138
    def binaries(self):
124
139
        """See `IDistroSeriesSourcePackageRelease`."""
125
 
        clauseTables = [
126
 
            'BinaryPackageRelease',
127
 
            'DistroArchSeries',
128
 
            'BinaryPackageBuild',
129
 
            'BinaryPackagePublishingHistory'
130
 
        ]
131
 
 
132
 
        query = """
133
 
        BinaryPackageRelease.build=BinaryPackageBuild.id AND
134
 
        DistroArchSeries.id =
135
 
            BinaryPackagePublishingHistory.distroarchseries AND
136
 
        BinaryPackagePublishingHistory.binarypackagerelease=
137
 
            BinaryPackageRelease.id AND
138
 
        DistroArchSeries.distroseries=%s AND
139
 
        BinaryPackagePublishingHistory.archive IN %s AND
140
 
        BinaryPackageBuild.source_package_release=%s
141
 
        """ % sqlvalues(self.distroseries,
142
 
                        self.distroseries.distribution.all_distro_archive_ids,
143
 
                        self.sourcepackagerelease)
144
 
 
145
 
        return BinaryPackageRelease.select(
146
 
                query, prejoinClauseTables=['BinaryPackageBuild'],
147
 
                orderBy=['-id'], clauseTables=clauseTables,
148
 
                distinct=True)
 
140
        # Avoid circular imports.
 
141
        from lp.soyuz.model.distroarchseries import DistroArchSeries
 
142
        store = Store.of(self.distroseries)
 
143
        result_row = (
 
144
            BinaryPackageRelease, BinaryPackageBuild, BinaryPackageName)
 
145
 
 
146
        tables = (
 
147
            BinaryPackageRelease,
 
148
            Join(
 
149
                BinaryPackageBuild,
 
150
                BinaryPackageBuild.id == BinaryPackageRelease.buildID),
 
151
            Join(
 
152
                BinaryPackagePublishingHistory,
 
153
                BinaryPackageRelease.id ==
 
154
                BinaryPackagePublishingHistory.binarypackagereleaseID),
 
155
            Join(
 
156
                DistroArchSeries,
 
157
                DistroArchSeries.id ==
 
158
                BinaryPackagePublishingHistory.distroarchseriesID),
 
159
            Join(
 
160
                BinaryPackageName,
 
161
                BinaryPackageName.id ==
 
162
                BinaryPackageRelease.binarypackagenameID))
 
163
        archive_ids = list(
 
164
            self.distroseries.distribution.all_distro_archive_ids)
 
165
        binaries = store.using(*tables).find(
 
166
            result_row,
 
167
            And(
 
168
                DistroArchSeries.distroseriesID == self.distroseries.id,
 
169
                BinaryPackagePublishingHistory.archiveID.is_in(archive_ids),
 
170
                BinaryPackageBuild.source_package_release ==
 
171
                self.sourcepackagerelease))
 
172
        binaries.order_by(Desc(BinaryPackageRelease.id)).config(distinct=True)
 
173
        return DecoratedResultSet(binaries, itemgetter(0))
149
174
 
150
175
    @property
151
176
    def changesfile(self):