1
# Copyright 2009-2011 Canonical Ltd. This software is licensed under the
1
# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
2
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
4
"""Database garbage collection."""
88
from lp.soyuz.model.sourcepackagerelease import SourcePackageRelease
88
89
from lp.translations.interfaces.potemplate import IPOTemplateSet
89
90
from lp.translations.model.potmsgset import POTMsgSet
90
91
from lp.translations.model.potranslation import POTranslation
875
876
self._update_oldest()
879
class SourcePackageReleaseDscBinariesUpdater(TunableLoop):
880
"""Fix incorrect values for SourcePackageRelease.dsc_binaries."""
882
maximum_chunk_size = 1000
884
def __init__(self, log, abort_time=None):
885
super(SourcePackageReleaseDscBinariesUpdater, self).__init__(
887
self.store = IMasterStore(SourcePackageRelease)
890
SourcePackageRelease.id,
891
# Get all SPR IDs which have an incorrectly-separated
892
# dsc_binaries value (space rather than comma-space).
893
SQL("dsc_binaries ~ '[a-z0-9+.-] '"),
894
# Skip rows with dsc_binaries in dependency relationship
895
# format. This is a different bug.
896
SQL("dsc_binaries NOT LIKE '%(%'")))
899
"""See `TunableLoop`."""
900
return len(self.ids) == 0
902
def __call__(self, chunk_size):
903
"""See `TunableLoop`."""
904
chunk_size = int(chunk_size + 0.5)
905
chunk_ids = self.ids[:chunk_size]
906
del self.ids[:chunk_size]
907
self.store.execute("""
908
UPDATE SourcePackageRelease
909
SET dsc_binaries = regexp_replace(
910
dsc_binaries, '([a-z0-9+.-]) ', E'\\\\1, ', 'g')
911
WHERE id IN %s""" % sqlvalues(chunk_ids), noresult=True)
878
915
class SuggestiveTemplatesCacheUpdater(TunableLoop):
879
916
"""Refresh the SuggestivePOTemplate cache.
1239
1276
ObsoleteBugAttachmentPruner,
1240
1277
OldTimeLimitedTokenDeleter,
1241
1278
RevisionAuthorEmailLinker,
1279
SourcePackageReleaseDscBinariesUpdater,
1242
1280
SuggestiveTemplatesCacheUpdater,
1243
1281
POTranslationPruner,
1244
1282
UnusedPOTMsgSetPruner,