~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-06 11:52:07 UTC
  • mto: This revision was merged to the branch mainline in revision 14646.
  • Revision ID: cjwatson@canonical.com-20120106115207-tf2lyncxv085pclt
Fix SourcePackageReleaseDscBinariesUpdater: round chunk_size to int.

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.store = IMasterStore(SourcePackageRelease)
 
888
        self.ids = list(
 
889
            self.store.find(
 
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 '%(%'")))
 
897
 
 
898
    def isDone(self):
 
899
        """See `TunableLoop`."""
 
900
        return len(self.ids) == 0
 
901
 
 
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)
 
912
        transaction.commit()
 
913
 
 
914
 
878
915
class SuggestiveTemplatesCacheUpdater(TunableLoop):
879
916
    """Refresh the SuggestivePOTemplate cache.
880
917
 
1239
1276
        ObsoleteBugAttachmentPruner,
1240
1277
        OldTimeLimitedTokenDeleter,
1241
1278
        RevisionAuthorEmailLinker,
 
1279
        SourcePackageReleaseDscBinariesUpdater,
1242
1280
        SuggestiveTemplatesCacheUpdater,
1243
1281
        POTranslationPruner,
1244
1282
        UnusedPOTMsgSetPruner,