Merge lp:~allenap/launchpad/is-user-affected-performance into lp:launchpad

Proposed by Gavin Panella
Status: Merged
Merged at revision: not available
Proposed branch: lp:~allenap/launchpad/is-user-affected-performance
Merge into: lp:launchpad
Diff against target: 79 lines (+17/-9)
2 files modified
lib/lp/bugs/doc/bug.txt (+7/-3)
lib/lp/bugs/model/bug.py (+10/-6)
To merge this branch: bzr merge lp:~allenap/launchpad/is-user-affected-performance
Reviewer Review Type Date Requested Status
Abel Deuring (community) code Approve
Review via email: mp+16027@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) wrote :

Add a __storm_primary__ setting to BugAffectsPerson so that it's possible to do store.get(BugAffectsPerson, (bug_id, person_id)), which can hit the Storm cache. I've also modified Bug._getAffectedPerson() to do just that.

Revision history for this message
Abel Deuring (adeuring) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/doc/bug.txt'
2--- lib/lp/bugs/doc/bug.txt 2009-11-25 13:22:01 +0000
3+++ lib/lp/bugs/doc/bug.txt 2009-12-12 09:49:17 +0000
4@@ -1194,8 +1194,9 @@
5 >>> affected_user = factory.makePerson(name='bruce-dickinson')
6 >>> unaffected_user = factory.makePerson(name='blaze-bayley')
7
8-Initially, only the bug reporter is marked as affected. Other users are neither
9-marked as affected nor as unaffected.
10+Initially, only the bug reporter is marked as affected. Other users,
11+including the anonymous user, are neither marked as affected nor as
12+unaffected.
13
14 >>> print test_bug.isUserAffected(test_bug.owner)
15 True
16@@ -1203,6 +1204,9 @@
17 >>> print test_bug.isUserAffected(affected_user)
18 None
19
20+ >>> print test_bug.isUserAffected(None)
21+ None
22+
23 When we mark a bug as affecting a new user, the affected_users_count
24 increments.
25
26@@ -1248,7 +1252,7 @@
27 paul-dianno
28
29 >>> unaffecting_bug = factory.makeBug()
30- >>> print unaffecting_bug.users_affected
31+ >>> print list(unaffecting_bug.users_affected)
32 [<Person at ...>]
33
34
35
36=== modified file 'lib/lp/bugs/model/bug.py'
37--- lib/lp/bugs/model/bug.py 2009-12-10 14:20:36 +0000
38+++ lib/lp/bugs/model/bug.py 2009-12-12 09:49:17 +0000
39@@ -98,6 +98,7 @@
40 from lp.registry.interfaces.productseries import IProductSeries
41 from lp.registry.interfaces.sourcepackage import ISourcePackage
42 from lp.registry.model.mentoringoffer import MentoringOffer
43+from lp.registry.model.person import Person
44 from lp.registry.model.pillar import pillar_sort_key
45
46
47@@ -262,8 +263,9 @@
48 @property
49 def users_affected(self):
50 """See `IBug`."""
51- return [bap.person for bap
52- in Store.of(self).find(BugAffectsPerson, bug=self)]
53+ return Store.of(self).find(
54+ Person, BugAffectsPerson.person == Person.id,
55+ BugAffectsPerson.bug == self)
56
57 @property
58 def indexed_messages(self):
59@@ -1307,10 +1309,11 @@
60 :param user: An `IPerson` that may be affected by the bug.
61 :return: An `IBugAffectsPerson` or None.
62 """
63- return Store.of(self).find(
64- BugAffectsPerson,
65- And(BugAffectsPerson.bug == self,
66- BugAffectsPerson.person == user)).one()
67+ if user is None:
68+ return None
69+ else:
70+ return Store.of(self).get(
71+ BugAffectsPerson, (self.id, user.id))
72
73 def isUserAffected(self, user):
74 """See `IBug`."""
75@@ -1674,3 +1677,4 @@
76 bug = ForeignKey(dbName='bug', foreignKey='Bug', notNull=True)
77 person = ForeignKey(dbName='person', foreignKey='Person', notNull=True)
78 affected = BoolCol(notNull=True, default=True)
79+ __storm_primary__ = "bugID", "personID"