Merge lp:~thumper/launchpad/revision-karma-fix into lp:launchpad

Proposed by Tim Penhey
Status: Merged
Merged at revision: not available
Proposed branch: lp:~thumper/launchpad/revision-karma-fix
Merge into: lp:launchpad
Diff against target: 37 lines (+13/-7)
1 file modified
lib/lp/code/scripts/revisionkarma.py (+13/-7)
To merge this branch: bzr merge lp:~thumper/launchpad/revision-karma-fix
Reviewer Review Type Date Requested Status
Michael Hudson-Doyle Approve
Review via email: mp+16890@code.launchpad.net

Commit message

Break out of the loop if karma is ever not allocated.

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

The count added before is too inefficient so removed it.

Changed the looping logic, and stop if we ever fail to allocate karma as it will infinite-loop otherwise.

If it does die, it gives us the revision_id from which to start debugging.

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

I guess you could even say logger.critical(), but it looks fine.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/code/scripts/revisionkarma.py'
--- lib/lp/code/scripts/revisionkarma.py 2010-01-05 01:51:56 +0000
+++ lib/lp/code/scripts/revisionkarma.py 2010-01-06 04:11:20 +0000
@@ -39,20 +39,26 @@
39 count = 039 count = 0
40 revision_set = getUtility(IRevisionSet)40 revision_set = getUtility(IRevisionSet)
41 # Break into bits.41 # Break into bits.
42 result_set = revision_set.getRevisionsNeedingKarmaAllocated()42 while True:
43 self.logger.info("%d revisions to update", result_set.count())43 revisions = list(
44 revisions = list(result_set[:100])44 revision_set.getRevisionsNeedingKarmaAllocated()[:100])
45 while len(revisions) > 0:45 if len(revisions) == 0:
46 break
46 for revision in revisions:47 for revision in revisions:
47 # Find the appropriate branch, and allocate karma to it.48 # Find the appropriate branch, and allocate karma to it.
48 # Make sure we don't grab a junk branch though, as we don't49 # Make sure we don't grab a junk branch though, as we don't
49 # allocate karma for junk branches.50 # allocate karma for junk branches.
50 branch = revision.getBranch(51 branch = revision.getBranch(
51 allow_private=True, allow_junk=False)52 allow_private=True, allow_junk=False)
52 revision.allocateKarma(branch)53 karma = revision.allocateKarma(branch)
54 if karma is None:
55 error_msg = (
56 'No karma generated for revid: %s (%s)' %
57 (revision.revision_id, revision.id))
58 self.logger.critical(error_msg)
59 # Stop now to avoid infinite loop.
60 raise AssertionError(error_msg)
53 count += 161 count += 1
54 self.logger.debug("%s processed", count)62 self.logger.debug("%s processed", count)
55 transaction.commit()63 transaction.commit()
56 revisions = list(
57 revision_set.getRevisionsNeedingKarmaAllocated()[:100])
58 self.logger.info("Finished updating revision karma")64 self.logger.info("Finished updating revision karma")