~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/scripts/garbo.py

  • Committer: Colin Watson
  • Date: 2012-01-05 14:21:46 UTC
  • mto: This revision was merged to the branch mainline in revision 14643.
  • Revision ID: cjwatson@canonical.com-20120105142146-v2odsixhltybljzb
Add garbo job to clean up broken SPR.dsc_binaries values.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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).
3
3
 
4
4
"""Database garbage collection."""
85
85
    MAIN_STORE,
86
86
    MASTER_FLAVOR,
87
87
    )
 
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()
876
877
 
877
878
 
 
879
class SourcePackageReleaseDscBinariesUpdater(TunableLoop):
 
880
    """Fix incorrect values for SourcePackageRelease.dsc_binaries."""
 
881
 
 
882
    maximum_chunk_size = 1000
 
883
 
 
884
    def __init__(self, log, abort_time=None):
 
885
        super(SourcePackageReleaseDscBinariesUpdater, self).__init__(
 
886
            log, abort_time)
 
887
        self.offset = 0
 
888
        self.store = IMasterStore(SourcePackageRelease)
 
889
        self.store.execute("DROP TABLE IF EXISTS MatchedSourcePackageRelease")
 
890
        self.store.execute("""
 
891
            CREATE TEMPORARY TABLE MatchedSourcePackageRelease AS
 
892
            SELECT id AS spr
 
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 '%(%'
 
900
            """, noresult=True)
 
901
        self.store.execute("""
 
902
            CREATE INDEX matchedsourcepackagerelease__spr__idx
 
903
            ON MatchedSourcePackageRelease(spr)
 
904
            """, noresult=True)
 
905
        self.matched_spr_count = self.store.execute("""
 
906
            SELECT COUNT(*) FROM MatchedSourcePackageRelease
 
907
            """).get_one()[0]
 
908
 
 
909
    def isDone(self):
 
910
        """See `TunableLoop`."""
 
911
        return self.offset >= self.matched_spr_count
 
912
 
 
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')
 
919
            FROM (
 
920
                SELECT spr
 
921
                FROM MatchedSourcePackageRelease
 
922
                ORDER BY spr
 
923
                OFFSET %d
 
924
                LIMIT %d
 
925
                ) AS MatchedSourcePackageRelease
 
926
            WHERE SourcePackageRelease.id = MatchedSourcePackageRelease.spr
 
927
            """ % (self.offset, chunk_size), noresult=True)
 
928
        self.offset += chunk_size
 
929
        transaction.commit()
 
930
 
 
931
 
878
932
class SuggestiveTemplatesCacheUpdater(TunableLoop):
879
933
    """Refresh the SuggestivePOTemplate cache.
880
934
 
1239
1293
        ObsoleteBugAttachmentPruner,
1240
1294
        OldTimeLimitedTokenDeleter,
1241
1295
        RevisionAuthorEmailLinker,
 
1296
        SourcePackageReleaseDscBinariesUpdater,
1242
1297
        SuggestiveTemplatesCacheUpdater,
1243
1298
        POTranslationPruner,
1244
1299
        UnusedPOTMsgSetPruner,