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__(
888
self.store = IMasterStore(SourcePackageRelease)
889
self.store.execute("DROP TABLE IF EXISTS MatchedSourcePackageRelease")
890
self.store.execute("""
891
CREATE TEMPORARY TABLE MatchedSourcePackageRelease AS
893
FROM SourcePackageRelease
894
-- Get all SPR IDs which have an incorrectly-separated
895
-- dsc_binaries value (space rather than comma-space).
896
WHERE dsc_binaries ~ '[a-z0-9+.-] '
897
-- Skip rows with dsc_binaries in dependency relationship
898
-- format. This is a different bug.
899
AND dsc_binaries NOT LIKE '%(%'
901
self.store.execute("""
902
CREATE INDEX matchedsourcepackagerelease__spr__idx
903
ON MatchedSourcePackageRelease(spr)
905
self.matched_spr_count = self.store.execute("""
906
SELECT COUNT(*) FROM MatchedSourcePackageRelease
910
"""See `TunableLoop`."""
911
return self.offset >= self.matched_spr_count
913
def __call__(self, chunk_size):
914
"""See `TunableLoop`."""
915
self.store.execute("""
916
UPDATE SourcePackageRelease
917
SET dsc_binaries = regexp_replace(
918
dsc_binaries, '([a-z0-9+.-]) ', E'\\\\1, ', 'g')
921
FROM MatchedSourcePackageRelease
925
) AS MatchedSourcePackageRelease
926
WHERE SourcePackageRelease.id = MatchedSourcePackageRelease.spr
927
""" % (self.offset, chunk_size), noresult=True)
928
self.offset += chunk_size
878
932
class SuggestiveTemplatesCacheUpdater(TunableLoop):
879
933
"""Refresh the SuggestivePOTemplate cache.
1239
1293
ObsoleteBugAttachmentPruner,
1240
1294
OldTimeLimitedTokenDeleter,
1241
1295
RevisionAuthorEmailLinker,
1296
SourcePackageReleaseDscBinariesUpdater,
1242
1297
SuggestiveTemplatesCacheUpdater,
1243
1298
POTranslationPruner,
1244
1299
UnusedPOTMsgSetPruner,