Merge lp:~wgrant/launchpad/improved-bugremovesubscriptions-job into lp:launchpad

Proposed by William Grant on 2012-06-15
Status: Merged
Approved by: William Grant on 2012-06-15
Approved revision: no longer in the source branch.
Merged at revision: 15430
Proposed branch: lp:~wgrant/launchpad/improved-bugremovesubscriptions-job
Merge into: lp:launchpad
Diff against target: 101 lines (+25/-23)
2 files modified
lib/lp/registry/model/sharingjob.py (+19/-19)
lib/lp/registry/tests/test_sharingjob.py (+6/-4)
To merge this branch: bzr merge lp:~wgrant/launchpad/improved-bugremovesubscriptions-job
Reviewer Review Type Date Requested Status
Ian Booth (community) 2012-06-15 Approve on 2012-06-15
Review via email: mp+110480@code.launchpad.net

Commit Message

Optimise RemoveBugSubscriptionsJob's core query and improve its repr.

Description of the Change

This branch makes two quick fixes to RemoveBugSubscriptionsJob:

 - Change the core query to JOIN BugTaskFlat rather than using an IN subquery. Much more optimisable.
 - Improve the operation description and repr to include all relevant information, and use unique names rather than displaynames.

To post a comment you must log in.
Ian Booth (wallyworld) wrote :

Look great.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/model/sharingjob.py'
2--- lib/lp/registry/model/sharingjob.py 2012-06-15 02:27:19 +0000
3+++ lib/lp/registry/model/sharingjob.py 2012-06-15 07:23:30 +0000
4@@ -24,6 +24,7 @@
5 from storm.expr import (
6 And,
7 In,
8+ Join,
9 Not,
10 Or,
11 Select,
12@@ -168,15 +169,9 @@
13 self.context = job
14
15 def __repr__(self):
16- if self.grantee:
17- return '<%(job_type)s job for %(grantee)s and %(pillar)s>' % {
18- 'job_type': self.context.job_type.name,
19- 'grantee': self.grantee.displayname,
20- 'pillar': self.pillar_text,
21- }
22- else:
23- return '<%(job_type)s job>' % {
24- 'job_type': self.context.job_type.name,
25+ return '<%(job_type)s job %(desc)s>' % {
26+ 'job_type': self.context.job_type.name,
27+ 'desc': self.getOperationDescription(),
28 }
29
30 @property
31@@ -305,7 +300,16 @@
32 return list(result)
33
34 def getOperationDescription(self):
35- return 'removing subscriptions for bugs %s' % self.bug_ids
36+ info = {
37+ 'information_types': [t.name for t in self.information_types],
38+ 'requestor': self.requestor.name,
39+ 'bug_ids': self.bug_ids,
40+ 'pillar': getattr(self.pillar, 'name', None),
41+ 'grantee': getattr(self.grantee, 'name', None)
42+ }
43+ return (
44+ 'reconciling subscriptions for %s' % ', '.join(
45+ '%s=%s' % (k, v) for (k, v) in sorted(info.items()) if v))
46
47 def run(self):
48 """See `IRemoveBugSubscriptionsJob`."""
49@@ -332,20 +336,16 @@
50 filters.append(
51 BugTaskFlat.distribution == self.distro)
52
53- subscriptions_filter = [
54- In(BugSubscription.bug_id,
55- Select(BugTaskFlat.bug_id, where=And(*filters)))]
56 if self.grantee:
57- subscriptions_filter.append(
58+ filters.append(
59 In(BugSubscription.person_id,
60 Select(
61 TeamParticipation.personID,
62- where=TeamParticipation.team == self.grantee))
63- )
64- subscriptions = IStore(BugSubscription).find(
65+ where=TeamParticipation.team == self.grantee)))
66+ subscriptions = IStore(BugSubscription).using(
67 BugSubscription,
68- *subscriptions_filter
69- )
70+ Join(BugTaskFlat, BugTaskFlat.bug_id == BugSubscription.bug_id)
71+ ).find(BugSubscription, *filters).config(distinct=True)
72 for sub in subscriptions:
73 sub.bug.unsubscribe(
74 sub.person, self.requestor, ignore_permissions=True)
75
76=== modified file 'lib/lp/registry/tests/test_sharingjob.py'
77--- lib/lp/registry/tests/test_sharingjob.py 2012-06-15 00:42:38 +0000
78+++ lib/lp/registry/tests/test_sharingjob.py 2012-06-15 07:23:30 +0000
79@@ -91,16 +91,18 @@
80 layer = DatabaseFunctionalLayer
81
82 def _makeJob(self):
83- bug = self.factory.makeBug()
84- requestor = self.factory.makePerson()
85+ self.bug = self.factory.makeBug()
86+ self.requestor = self.factory.makePerson()
87 job = getUtility(IRemoveBugSubscriptionsJobSource).create(
88- requestor, bugs=[bug])
89+ self.requestor, bugs=[self.bug])
90 return job
91
92 def test_repr(self):
93 job = self._makeJob()
94 self.assertEqual(
95- '<REMOVE_BUG_SUBSCRIPTIONS job>',
96+ '<REMOVE_BUG_SUBSCRIPTIONS job reconciling subscriptions for '
97+ 'bug_ids=[%d], requestor=%s>'
98+ % (self.bug.id, self.requestor.name),
99 repr(job))
100
101 def test_create_success(self):