~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-10-06 01:24:37 UTC
  • mfrom: (14039.1.12 bug-759467)
  • Revision ID: launchpad@pqm.canonical.com-20111006012437-x4xn9cohnyp5ztlx
[r=gmb][bug=759467] [r=gmb][bug=759467] Store
 INCOMPLETE_WITH_RESPONSE and INCOMPLETE_WITHOUT_RESPONSE for BugTask status
 to make queries more efficient.

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
    )
60
60
from lp.answers.model.answercontact import AnswerContact
61
61
from lp.bugs.interfaces.bug import IBugSet
 
62
from lp.bugs.interfaces.bugtask import (
 
63
    BugTaskStatus,
 
64
    BugTaskStatusSearch,
 
65
    )
62
66
from lp.bugs.model.bug import Bug
63
67
from lp.bugs.model.bugattachment import BugAttachment
64
68
from lp.bugs.model.bugnotification import BugNotification
 
69
from lp.bugs.model.bugtask import BugTask
65
70
from lp.bugs.model.bugwatch import BugWatchActivity
66
71
from lp.bugs.scripts.checkwatches.scheduler import (
67
72
    BugWatchScheduler,
808
813
        transaction.commit()
809
814
 
810
815
 
 
816
class BugTaskIncompleteMigrator(TunableLoop):
 
817
    """Migrate BugTaskStatus 'INCOMPLETE' to a concrete WITH/WITHOUT value."""
 
818
 
 
819
    maximum_chunk_size = 20000
 
820
    minimum_chunk_size = 100
 
821
 
 
822
    def __init__(self, log, abort_time=None, max_heat_age=None):
 
823
        super(BugTaskIncompleteMigrator, self).__init__(log, abort_time)
 
824
        self.transaction = transaction
 
825
        self.total_processed = 0
 
826
        self.is_done = False
 
827
        self.offset = 0
 
828
        self.store = IMasterStore(BugTask)
 
829
        self.query = self.store.find(
 
830
            (BugTask, Bug),
 
831
            BugTask._status == BugTaskStatus.INCOMPLETE,
 
832
            BugTask.bugID == Bug.id)
 
833
 
 
834
    def isDone(self):
 
835
        """See `ITunableLoop`."""
 
836
        return self.query.is_empty()
 
837
 
 
838
    def __call__(self, chunk_size):
 
839
        """See `ITunableLoop`."""
 
840
        transaction.begin()
 
841
        tasks = list(self.query[:chunk_size])
 
842
        for (task, bug) in tasks:
 
843
            if (bug.date_last_message is None or
 
844
                task.date_incomplete > bug.date_last_message):
 
845
                task._status = BugTaskStatusSearch.INCOMPLETE_WITHOUT_RESPONSE
 
846
            else:
 
847
                task._status = BugTaskStatusSearch.INCOMPLETE_WITH_RESPONSE
 
848
        self.log.debug("Updated status on %d tasks" % len(tasks))
 
849
        transaction.commit()
 
850
 
 
851
 
811
852
class BugWatchActivityPruner(BulkPruner):
812
853
    """A TunableLoop to prune BugWatchActivity entries."""
813
854
    target_table_class = BugWatchActivity
1270
1311
        BugHeatUpdater,
1271
1312
        SourcePackagePublishingHistorySPNPopulator,
1272
1313
        BinaryPackagePublishingHistoryBPNPopulator,
 
1314
        BugTaskIncompleteMigrator,
1273
1315
        ]
1274
1316
    experimental_tunable_loops = []
1275
1317