~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

[r=wallyworld][bug=854657] Add a garbo job to populate the new
        transitively_private column in the branch table.

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
    MAX_SAMPLE_SIZE,
70
70
    )
71
71
from lp.code.interfaces.revision import IRevisionSet
 
72
from lp.code.model.branch import Branch
72
73
from lp.code.model.codeimportevent import CodeImportEvent
73
74
from lp.code.model.codeimportresult import CodeImportResult
74
75
from lp.code.model.revision import (
747
748
        """
748
749
 
749
750
 
 
751
class PopulateBranchTransitivelyPrivate(TunableLoop):
 
752
    """Populated the branch column transitively_private values.
 
753
 
 
754
    Only needed until they are all set, after that triggers will maintain it.
 
755
    """
 
756
 
 
757
    maximum_chunk_size = 10000
 
758
 
 
759
    def __init__(self, log, abort_time=None):
 
760
        super_instance = super(PopulateBranchTransitivelyPrivate, self)
 
761
        super_instance.__init__(log, abort_time)
 
762
        self.store = IMasterStore(Branch)
 
763
        self.isDone = IMasterStore(Branch).find(
 
764
            Branch, Branch.transitively_private == None).is_empty
 
765
 
 
766
    def __call__(self, chunk_size):
 
767
        """See `ITunableLoop`."""
 
768
        transaction.begin()
 
769
        updated = self.store.execute("""
 
770
            SELECT update_transitively_private(id) FROM branch
 
771
            WHERE transitively_private IS NULL LIMIT %s
 
772
            """ % int(chunk_size)
 
773
            ).rowcount
 
774
        self.log.debug("Updated %s branches." % updated)
 
775
        transaction.commit()
 
776
 
 
777
 
750
778
class BugHeatUpdater(TunableLoop):
751
779
    """A `TunableLoop` for bug heat calculations."""
752
780
 
1259
1287
        BugHeatUpdater,
1260
1288
        SourcePackagePublishingHistorySPNPopulator,
1261
1289
        BinaryPackagePublishingHistoryBPNPopulator,
 
1290
        PopulateBranchTransitivelyPrivate,
1262
1291
        ]
1263
1292
    experimental_tunable_loops = []
1264
1293