Merge lp:~cjwatson/launchpad/close-account-bugsummary into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18911
Proposed branch: lp:~cjwatson/launchpad/close-account-bugsummary
Merge into: lp:launchpad
Diff against target: 78 lines (+45/-0)
2 files modified
lib/lp/registry/scripts/closeaccount.py (+4/-0)
lib/lp/registry/scripts/tests/test_closeaccount.py (+41/-0)
To merge this branch: bzr merge lp:~cjwatson/launchpad/close-account-bugsummary
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+364916@code.launchpad.net

Commit message

Skip BugSummary.viewed_by in close-account, since it's only updated when the journal is rolled up.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
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/registry/scripts/closeaccount.py'
2--- lib/lp/registry/scripts/closeaccount.py 2019-03-12 11:45:41 +0000
3+++ lib/lp/registry/scripts/closeaccount.py 2019-03-21 17:41:21 +0000
4@@ -148,6 +148,10 @@
5 ('usertouseremail', 'recipient'),
6 ('usertouseremail', 'sender'),
7 ('xref', 'creator'),
8+
9+ # This is maintained by trigger functions and a garbo job. It
10+ # doesn't need to be updated immediately.
11+ ('bugsummary', 'viewed_by'),
12 }
13 reference_names = {
14 (src_tab, src_col) for src_tab, src_col, _, _, _, _ in references}
15
16=== modified file 'lib/lp/registry/scripts/tests/test_closeaccount.py'
17--- lib/lp/registry/scripts/tests/test_closeaccount.py 2019-03-11 14:51:16 +0000
18+++ lib/lp/registry/scripts/tests/test_closeaccount.py 2019-03-21 17:41:21 +0000
19@@ -10,6 +10,8 @@
20 import six
21 from storm.store import Store
22 from testtools.matchers import (
23+ MatchesSetwise,
24+ MatchesStructure,
25 Not,
26 StartsWith,
27 )
28@@ -18,7 +20,9 @@
29 from zope.security.proxy import removeSecurityProxy
30
31 from lp.answers.enums import QuestionStatus
32+from lp.app.enums import InformationType
33 from lp.app.interfaces.launchpad import ILaunchpadCelebrities
34+from lp.bugs.model.bugsummary import BugSummary
35 from lp.hardwaredb.interfaces.hwdb import (
36 HWBus,
37 IHWDeviceSet,
38@@ -407,3 +411,40 @@
39 other_submission, hw_submission_set.getBySubmissionKey(other_key))
40 self.assertEqual(
41 [other_submission_device], list(other_submission.devices))
42+
43+ def test_skips_bug_summary(self):
44+ person = self.factory.makePerson()
45+ other_person = self.factory.makePerson()
46+ bug = self.factory.makeBug(information_type=InformationType.USERDATA)
47+ bug.subscribe(person, bug.owner)
48+ bug.subscribe(other_person, bug.owner)
49+ store = Store.of(bug)
50+ summaries = list(store.find(
51+ BugSummary,
52+ BugSummary.viewed_by_id.is_in([person.id, other_person.id])))
53+ self.assertThat(summaries, MatchesSetwise(
54+ MatchesStructure.byEquality(count=1, viewed_by=person),
55+ MatchesStructure.byEquality(count=1, viewed_by=other_person)))
56+ person_id = person.id
57+ account_id = person.account.id
58+ script = self.makeScript([six.ensure_str(person.name)])
59+ with dbuser('launchpad'):
60+ self.runScript(script)
61+ self.assertRemoved(account_id, person_id)
62+ # BugSummaryJournal has been updated, but BugSummary hasn't yet.
63+ summaries = list(store.find(
64+ BugSummary,
65+ BugSummary.viewed_by_id.is_in([person.id, other_person.id])))
66+ self.assertThat(summaries, MatchesSetwise(
67+ MatchesStructure.byEquality(count=1, viewed_by=person),
68+ MatchesStructure.byEquality(count=1, viewed_by=other_person),
69+ MatchesStructure.byEquality(count=-1, viewed_by=person)))
70+ # If we force an update (the equivalent of the
71+ # BugSummaryJournalRollup garbo job), that's enough to get rid of
72+ # the reference.
73+ store.execute('SELECT bugsummary_rollup_journal()')
74+ summaries = list(store.find(
75+ BugSummary,
76+ BugSummary.viewed_by_id.is_in([person.id, other_person.id])))
77+ self.assertThat(summaries, MatchesSetwise(
78+ MatchesStructure.byEquality(viewed_by=other_person)))