1
# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
1
# Copyright 2009-2011 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
89
88
from lp.translations.interfaces.potemplate import IPOTemplateSet
90
89
from lp.translations.model.potmsgset import POTMsgSet
91
90
from lp.translations.model.potranslation import POTranslation
876
875
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)
915
878
class SuggestiveTemplatesCacheUpdater(TunableLoop):
916
879
"""Refresh the SuggestivePOTemplate cache.
1276
1239
ObsoleteBugAttachmentPruner,
1277
1240
OldTimeLimitedTokenDeleter,
1278
1241
RevisionAuthorEmailLinker,
1279
SourcePackageReleaseDscBinariesUpdater,
1280
1242
SuggestiveTemplatesCacheUpdater,
1281
1243
POTranslationPruner,
1282
1244
UnusedPOTMsgSetPruner,