Merge lp:~sinzui/launchpad/revision-karma-2 into lp:launchpad

Proposed by Curtis Hovey on 2012-12-04
Status: Merged
Approved by: Curtis Hovey on 2012-12-04
Approved revision: no longer in the source branch.
Merged at revision: 16339
Proposed branch: lp:~sinzui/launchpad/revision-karma-2
Merge into: lp:launchpad
Diff against target: 74 lines (+12/-19)
3 files modified
lib/lp/code/model/revision.py (+1/-1)
lib/lp/code/model/tests/test_revision.py (+9/-0)
lib/lp/code/scripts/revisionkarma.py (+2/-18)
To merge this branch: bzr merge lp:~sinzui/launchpad/revision-karma-2
Reviewer Review Type Date Requested Status
Richard Harding (community) 2012-12-04 Approve on 2012-12-04
Review via email: mp+137906@code.launchpad.net

Commit Message

Ensure allocated_karma() is called for all revisions

Description of the Change

allocate-revision-karma.py is having its DB connection reaped while it's
running, because the query in RevisionSet
getRevisionsNeedingKarmaAllocated is terribly slow.

Right now, we have 21.1 million revisions. 15.9 million of these are
flagged as not having karma allocated. These 15.9 million revisions are
the combination of revisions that have never been processed, or only
exist in +junk branches, or only exist in branches owned by invalid
people. Each run, the scanner needs to check all 15.9 million revisions.

--------------------------------------------------------------------

RULES

    Pre-implementation: stub
    * This is a follow up branch to address a case seen on qastaging.
      * The script assumes that returning None from allocateKarma()
        is bad because Lp will eternally process the revision. This
        is not bad anymore because the method has set rev.allocated_karma
        to True.
      * The script will look up the revision's branch, but since lookup
        ignores junk branches, the branch can be None. This is okay
        because we want to ensure rev.allocated_karma is still called
        to ensure Lp does not reprocess the revision.

QA

    * As a webops to run
      ./cronscripts/allocate-revision-karma.py
      for qastaging's script host (gandwana).
    * Verify there are no errors after a 5 minutes. The proc
      can be killed since we do not need to Verify all 15 million
      revisions.

LoC

    I have a 10,000 line credit this week.

LINT

    lib/lp/code/model/revision.py
    lib/lp/code/model/tests/test_revision.py
    lib/lp/code/scripts/revisionkarma.py

TEST

    ./bin/test -vc -t TestRevisionKarma lp.code.model.tests.test_revision
    ./bin/test -vc lp.code.scripts.tests.test_revisionkarma

IMPLEMENTATION

I updated allocateKarma() to not attempt to add karma if there is no
community branch for the revision. I updated the script to continue
processing revisions because the call to allocateKarma() did set
rev.allocated_karma to True.
    lib/lp/code/model/revision.py
    lib/lp/code/model/tests/test_revision.py
    lib/lp/code/scripts/revisionkarma.py

To post a comment you must log in.
Richard Harding (rharding) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/model/revision.py'
2--- lib/lp/code/model/revision.py 2012-12-03 18:33:11 +0000
3+++ lib/lp/code/model/revision.py 2012-12-04 16:31:31 +0000
4@@ -133,7 +133,7 @@
5 self.karma_allocated = True
6 # If we know who the revision author is, give them karma.
7 author = self.revision_author.person
8- if author is not None:
9+ if author is not None and branch is not None:
10 # Backdate the karma to the time the revision was created. If the
11 # revision_date on the revision is in future (for whatever weird
12 # reason) we will use the date_created from the revision (which
13
14=== modified file 'lib/lp/code/model/tests/test_revision.py'
15--- lib/lp/code/model/tests/test_revision.py 2012-12-03 19:37:01 +0000
16+++ lib/lp/code/model/tests/test_revision.py 2012-12-04 16:31:31 +0000
17@@ -171,6 +171,15 @@
18 karma = rev.allocateKarma(branch)
19 self.assertIs(None, karma)
20
21+ def test_allocateKarma_personal_branch_none(self):
22+ # Revisions only associated with junk branches don't get karma,
23+ # and the branch may be None because the revision_set does not
24+ # attempt to get junk branches.
25+ author = self.factory.makePerson()
26+ rev = self.factory.makeRevision(author=author)
27+ karma = rev.allocateKarma(None)
28+ self.assertIs(None, karma)
29+
30 def test_allocateKarma_package_branch(self):
31 # A revision on a package branch gets karma.
32 author = self.factory.makePerson()
33
34=== modified file 'lib/lp/code/scripts/revisionkarma.py'
35--- lib/lp/code/scripts/revisionkarma.py 2010-10-12 05:34:49 +0000
36+++ lib/lp/code/scripts/revisionkarma.py 2012-12-04 16:31:31 +0000
37@@ -1,4 +1,4 @@
38-# Copyright 2009 Canonical Ltd. This software is licensed under the
39+# Copyright 2009-2012 Canonical Ltd. This software is licensed under the
40 # GNU Affero General Public License version 3 (see the file LICENSE).
41
42 """The actual script class to allocate revisions."""
43@@ -23,15 +23,6 @@
44 There are a number of circumstances where this doesn't happen:
45 * The revision author is not linked to a Launchpad person
46 * The branch is +junk
47-
48- When a branch is moved from +junk to a project we want to be able to
49- allocate karma for the revisions that are now in the project.
50-
51- When a person validates an email address, a link is made with a
52- `RevisionAuthor` if the revision author has that email address. In
53- this situation we want to allocate karma for the revisions that have
54- the newly linked revision author as the and allocate karma for the
55- person.
56 """
57 self.logger.info("Updating revision karma")
58
59@@ -49,14 +40,7 @@
60 # allocate karma for junk branches.
61 branch = revision.getBranch(
62 allow_private=True, allow_junk=False)
63- karma = revision.allocateKarma(branch)
64- if karma is None:
65- error_msg = (
66- 'No karma generated for revid: %s (%s)' %
67- (revision.revision_id, revision.id))
68- self.logger.critical(error_msg)
69- # Stop now to avoid infinite loop.
70- raise AssertionError(error_msg)
71+ revision.allocateKarma(branch)
72 count += 1
73 self.logger.debug("%s processed", count)
74 transaction.commit()