~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-08-03 16:57:47 UTC
  • mfrom: (9893.6.56 trivial)
  • Revision ID: launchpad@pqm.canonical.com-20110803165747-mwpmhu8uj8al7256
[r=danilo][bug=820291] Work around Bug #820290 in BugHeatUpdater

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
 
40
40
from canonical.config import config
41
41
from canonical.database import postgresql
 
42
from canonical.database.constants import UTC_NOW
42
43
from canonical.database.sqlbase import (
43
44
    cursor,
44
45
    session_store,
726
727
class BugHeatUpdater(TunableLoop):
727
728
    """A `TunableLoop` for bug heat calculations."""
728
729
 
729
 
    maximum_chunk_size = 1000
 
730
    maximum_chunk_size = 5000
730
731
 
731
732
    def __init__(self, log, abort_time=None, max_heat_age=None):
732
733
        super(BugHeatUpdater, self).__init__(log, abort_time)
760
761
 
761
762
        See `ITunableLoop`.
762
763
        """
763
 
        # We multiply chunk_size by 1000 for the sake of doing updates
764
 
        # quickly.
765
 
        chunk_size = int(chunk_size * 1000)
766
 
 
767
 
        transaction.begin()
 
764
        chunk_size = int(chunk_size + 0.5)
768
765
        outdated_bugs = self._outdated_bugs[:chunk_size]
769
 
        self.log.debug("Updating heat for %s bugs" % outdated_bugs.count())
770
 
        outdated_bugs.set(
771
 
            heat=SQL('calculate_bug_heat(Bug.id)'),
772
 
            heat_last_updated=datetime.now(pytz.utc))
773
 
 
 
766
        # We don't use outdated_bugs.set() here to work around
 
767
        # Storm Bug #820290.
 
768
        outdated_bug_ids = [bug.id for bug in outdated_bugs]
 
769
        self.log.debug("Updating heat for %s bugs", len(outdated_bug_ids))
 
770
        IMasterStore(Bug).find(
 
771
            Bug, Bug.id.is_in(outdated_bug_ids)).set(
 
772
                heat=SQL('calculate_bug_heat(Bug.id)'),
 
773
                heat_last_updated=UTC_NOW)
774
774
        transaction.commit()
775
775
 
776
776