~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/registry/model/distribution.py

  • Committer: William Grant
  • Date: 2011-08-24 05:39:34 UTC
  • mto: This revision was merged to the branch mainline in revision 13785.
  • Revision ID: william.grant@canonical.com-20110824053934-49uetjp8xnb9sbh8
Move the four equivalent methods from Distribution to DistributionSourcePackageCache. No tests fixed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1129
1129
        return getUtility(IBinaryPackageBuildSet).getBuildsByArchIds(
1130
1130
            self, arch_ids, build_state, name, pocket)
1131
1131
 
1132
 
    def getSourcePackageCaches(self, archive=None):
1133
 
        """See `IDistribution`."""
1134
 
        if archive is not None:
1135
 
            archives = [archive.id]
1136
 
        else:
1137
 
            archives = self.all_distro_archive_ids
1138
 
 
1139
 
        caches = DistributionSourcePackageCache.select("""
1140
 
            distribution = %s AND
1141
 
            archive IN %s
1142
 
        """ % sqlvalues(self, archives),
1143
 
        orderBy="name",
1144
 
        prejoins=['sourcepackagename'])
1145
 
 
1146
 
        return caches
1147
 
 
1148
 
    def removeOldCacheItems(self, archive, log):
1149
 
        """See `IDistribution`."""
1150
 
 
1151
 
        # Get the set of source package names to deal with.
1152
 
        spns = set(SourcePackageName.select("""
1153
 
            SourcePackagePublishingHistory.distroseries =
1154
 
                DistroSeries.id AND
1155
 
            DistroSeries.distribution = %s AND
1156
 
            Archive.id = %s AND
1157
 
            SourcePackagePublishingHistory.archive = Archive.id AND
1158
 
            SourcePackagePublishingHistory.sourcepackagerelease =
1159
 
                SourcePackageRelease.id AND
1160
 
            SourcePackageRelease.sourcepackagename =
1161
 
                SourcePackageName.id AND
1162
 
            SourcePackagePublishingHistory.dateremoved is NULL AND
1163
 
            Archive.enabled = TRUE
1164
 
            """ % sqlvalues(self, archive),
1165
 
            distinct=True,
1166
 
            clauseTables=[
1167
 
                'Archive',
1168
 
                'DistroSeries',
1169
 
                'SourcePackagePublishingHistory',
1170
 
                'SourcePackageRelease']))
1171
 
 
1172
 
        # Remove the cache entries for packages we no longer publish.
1173
 
        for cache in self.getSourcePackageCaches(archive):
1174
 
            if cache.sourcepackagename not in spns:
1175
 
                log.debug(
1176
 
                    "Removing source cache for '%s' (%s)"
1177
 
                    % (cache.name, cache.id))
1178
 
                cache.destroySelf()
1179
 
 
1180
 
    def updateCompleteSourcePackageCache(self, archive, log, ztm,
1181
 
                                         commit_chunk=500):
1182
 
        """See `IDistribution`."""
1183
 
        # Do not create cache entries for disabled archives.
1184
 
        if not archive.enabled:
1185
 
            return
1186
 
 
1187
 
        # Get the set of source package names to deal with.
1188
 
        spns = list(SourcePackageName.select("""
1189
 
            SourcePackagePublishingHistory.distroseries =
1190
 
                DistroSeries.id AND
1191
 
            DistroSeries.distribution = %s AND
1192
 
            SourcePackagePublishingHistory.archive = %s AND
1193
 
            SourcePackagePublishingHistory.sourcepackagerelease =
1194
 
                SourcePackageRelease.id AND
1195
 
            SourcePackageRelease.sourcepackagename =
1196
 
                SourcePackageName.id AND
1197
 
            SourcePackagePublishingHistory.dateremoved is NULL
1198
 
            """ % sqlvalues(self, archive),
1199
 
            distinct=True,
1200
 
            orderBy="name",
1201
 
            clauseTables=['SourcePackagePublishingHistory', 'DistroSeries',
1202
 
                'SourcePackageRelease']))
1203
 
 
1204
 
        number_of_updates = 0
1205
 
        chunk_size = 0
1206
 
        for spn in spns:
1207
 
            log.debug("Considering source '%s'" % spn.name)
1208
 
            self.updateSourcePackageCache(spn, archive, log)
1209
 
            chunk_size += 1
1210
 
            number_of_updates += 1
1211
 
            if chunk_size == commit_chunk:
1212
 
                chunk_size = 0
1213
 
                log.debug("Committing")
1214
 
                ztm.commit()
1215
 
 
1216
 
        return number_of_updates
1217
 
 
1218
 
    def updateSourcePackageCache(self, sourcepackagename, archive, log):
1219
 
        """See `IDistribution`."""
1220
 
 
1221
 
        # Get the set of published sourcepackage releases.
1222
 
        sprs = list(SourcePackageRelease.select("""
1223
 
            SourcePackageRelease.sourcepackagename = %s AND
1224
 
            SourcePackageRelease.id =
1225
 
                SourcePackagePublishingHistory.sourcepackagerelease AND
1226
 
            SourcePackagePublishingHistory.distroseries =
1227
 
                DistroSeries.id AND
1228
 
            DistroSeries.distribution = %s AND
1229
 
            SourcePackagePublishingHistory.archive = %s AND
1230
 
            SourcePackagePublishingHistory.dateremoved is NULL
1231
 
            """ % sqlvalues(sourcepackagename, self, archive),
1232
 
            orderBy='id',
1233
 
            clauseTables=['SourcePackagePublishingHistory', 'DistroSeries'],
1234
 
            distinct=True))
1235
 
 
1236
 
        if len(sprs) == 0:
1237
 
            log.debug("No sources releases found.")
1238
 
            return
1239
 
 
1240
 
        # Find or create the cache entry.
1241
 
        cache = DistributionSourcePackageCache.selectOne("""
1242
 
            distribution = %s AND
1243
 
            archive = %s AND
1244
 
            sourcepackagename = %s
1245
 
            """ % sqlvalues(self, archive, sourcepackagename))
1246
 
        if cache is None:
1247
 
            log.debug("Creating new source cache entry.")
1248
 
            cache = DistributionSourcePackageCache(
1249
 
                archive=archive,
1250
 
                distribution=self,
1251
 
                sourcepackagename=sourcepackagename)
1252
 
 
1253
 
        # Make sure the name is correct.
1254
 
        cache.name = sourcepackagename.name
1255
 
 
1256
 
        # Get the sets of binary package names, summaries, descriptions.
1257
 
 
1258
 
        # XXX Julian 2007-04-03:
1259
 
        # This bit of code needs fixing up, it is doing stuff that
1260
 
        # really needs to be done in SQL, such as sorting and uniqueness.
1261
 
        # This would also improve the performance.
1262
 
        binpkgnames = set()
1263
 
        binpkgsummaries = set()
1264
 
        binpkgdescriptions = set()
1265
 
        sprchangelog = set()
1266
 
        for spr in sprs:
1267
 
            log.debug("Considering source version %s" % spr.version)
1268
 
            # changelog may be empty, in which case we don't want to add it
1269
 
            # to the set as the join would fail below.
1270
 
            if spr.changelog_entry is not None:
1271
 
                sprchangelog.add(spr.changelog_entry)
1272
 
            binpkgs = BinaryPackageRelease.select("""
1273
 
                BinaryPackageRelease.build = BinaryPackageBuild.id AND
1274
 
                BinaryPackageBuild.source_package_release = %s
1275
 
                """ % sqlvalues(spr.id),
1276
 
                clauseTables=['BinaryPackageBuild'])
1277
 
            for binpkg in binpkgs:
1278
 
                log.debug("Considering binary '%s'" % binpkg.name)
1279
 
                binpkgnames.add(binpkg.name)
1280
 
                binpkgsummaries.add(binpkg.summary)
1281
 
                binpkgdescriptions.add(binpkg.description)
1282
 
 
1283
 
        # Update the caches.
1284
 
        cache.binpkgnames = ' '.join(sorted(binpkgnames))
1285
 
        cache.binpkgsummaries = ' '.join(sorted(binpkgsummaries))
1286
 
        cache.binpkgdescriptions = ' '.join(sorted(binpkgdescriptions))
1287
 
        cache.changelog = ' '.join(sorted(sprchangelog))
1288
 
 
1289
1132
    def searchSourcePackageCaches(
1290
1133
        self, text, has_packaging=None, publishing_distroseries=None):
1291
1134
        """See `IDistribution`."""