Merge lp:~stevenk/launchpad/branch-information_type-garbo into lp:launchpad

Proposed by Steve Kowalik
Status: Merged
Approved by: William Grant
Approved revision: no longer in the source branch.
Merged at revision: 15206
Proposed branch: lp:~stevenk/launchpad/branch-information_type-garbo
Merge into: lp:launchpad
Prerequisite: lp:~stevenk/launchpad/branch-information_type-model
Diff against target: 100 lines (+51/-0)
2 files modified
lib/lp/scripts/garbo.py (+28/-0)
lib/lp/scripts/tests/test_garbo.py (+23/-0)
To merge this branch: bzr merge lp:~stevenk/launchpad/branch-information_type-garbo
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+104683@code.launchpad.net

Commit message

Add a garbo job to populate Branch.information_type.

Description of the change

Add a garbo job to populate Branch.information_type. Be very sneaky and use an SQL CASE statement to set it for purely speed reasons.

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/scripts/garbo.py'
2--- lib/lp/scripts/garbo.py 2012-04-25 14:10:24 +0000
3+++ lib/lp/scripts/garbo.py 2012-05-04 06:27:21 +0000
4@@ -51,6 +51,7 @@
5 MAX_SAMPLE_SIZE,
6 )
7 from lp.code.interfaces.revision import IRevisionSet
8+from lp.code.model.branch import Branch
9 from lp.code.model.codeimportevent import CodeImportEvent
10 from lp.code.model.codeimportresult import CodeImportResult
11 from lp.code.model.revision import (
12@@ -58,6 +59,7 @@
13 RevisionCache,
14 )
15 from lp.hardwaredb.model.hwdb import HWSubmission
16+from lp.registry.enums import InformationType
17 from lp.registry.model.person import Person
18 from lp.services.config import config
19 from lp.services.database import postgresql
20@@ -835,6 +837,31 @@
21 transaction.commit()
22
23
24+class BranchInformationTypeMigrator(TunableLoop):
25+ """A `TunableLoop` to populate information_type for all branches."""
26+
27+ maximum_chunk_size = 5000
28+
29+ def __init__(self, log, abort_time=None):
30+ super(BranchInformationTypeMigrator, self).__init__(log, abort_time)
31+ self.transaction = transaction
32+ self.store = IMasterStore(Branch)
33+
34+ def findBranches(self):
35+ return self.store.find(Branch, Branch.information_type == None)
36+
37+ def isDone(self):
38+ return self.findBranches().is_empty()
39+
40+ def __call__(self, chunk_size):
41+ self.findBranches()[:chunk_size].set(
42+ information_type=SQL(
43+ "CASE WHEN transitively_private THEN ? ELSE ? END",
44+ params=(InformationType.USERDATA.value,
45+ InformationType.PUBLIC.value)))
46+ self.transaction.commit()
47+
48+
49 class BugWatchActivityPruner(BulkPruner):
50 """A TunableLoop to prune BugWatchActivity entries."""
51 target_table_class = BugWatchActivity
52@@ -1382,6 +1409,7 @@
53 DuplicateSessionPruner,
54 BugHeatUpdater,
55 BugTaskFlattener,
56+ BranchInformationTypeMigrator,
57 ]
58 experimental_tunable_loops = []
59
60
61=== modified file 'lib/lp/scripts/tests/test_garbo.py'
62--- lib/lp/scripts/tests/test_garbo.py 2012-04-02 07:10:56 +0000
63+++ lib/lp/scripts/tests/test_garbo.py 2012-05-04 06:27:21 +0000
64@@ -55,6 +55,7 @@
65 )
66 from lp.code.model.codeimportevent import CodeImportEvent
67 from lp.code.model.codeimportresult import CodeImportResult
68+from lp.registry.enums import InformationType
69 from lp.registry.interfaces.distribution import IDistributionSet
70 from lp.registry.interfaces.person import IPersonSet
71 from lp.scripts.garbo import (
72@@ -1134,6 +1135,28 @@
73 'SELECT bugtask FROM BugTaskFlat WHERE bugtask = ?',
74 (task.id,)).get_one())
75
76+ def test_BranchInformationTypeMigrator_public(self):
77+ # A non-migrated public branch will have information_type set
78+ # correctly.
79+ switch_dbuser('testadmin')
80+ branch = self.factory.makeBranch()
81+ # Since creating a branch will set information_type, unset it.
82+ removeSecurityProxy(branch).information_type = None
83+ transaction.commit()
84+ self.runHourly()
85+ self.assertEqual(InformationType.PUBLIC, branch.information_type)
86+
87+ def test_BranchInformationTypeMigrator_private(self):
88+ # A non-migrated private branch will have information_type set
89+ # correctly.
90+ switch_dbuser('testadmin')
91+ branch = self.factory.makeBranch(private=True)
92+ # Since creating a branch will set information_type, unset it.
93+ removeSecurityProxy(branch).information_type = None
94+ transaction.commit()
95+ self.runHourly()
96+ self.assertEqual(InformationType.USERDATA, branch.information_type)
97+
98
99 class TestGarboTasks(TestCaseWithFactory):
100 layer = LaunchpadZopelessLayer