Merge lp:~stub/launchpad/oops-pruning into lp:launchpad

Proposed by Stuart Bishop on 2010-03-17
Status: Merged
Approved by: Gary Poster on 2010-03-18
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~stub/launchpad/oops-pruning
Merge into: lp:launchpad
Diff against target: 85 lines (+25/-12)
2 files modified
lib/canonical/launchpad/scripts/ftests/test_oops_prune.py (+9/-0)
lib/canonical/launchpad/scripts/oops.py (+16/-12)
To merge this branch: bzr merge lp:~stub/launchpad/oops-pruning
Reviewer Review Type Date Requested Status
Gary Poster (community) 2010-03-17 Approve on 2010-03-18
Review via email: mp+21536@code.launchpad.net

Commit Message

The OOPS pruner is fairly DB intensive and has no need to connect to the master database at all. Make it connect to the slave database instead.

Description of the Change

The OOPS pruner is fairly DB intensive and has no need to connect to the master database at all. Make it connect to the slave database instead.

To post a comment you must log in.
Gary Poster (gary) wrote :

Great, thank you!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/launchpad/scripts/ftests/test_oops_prune.py'
2--- lib/canonical/launchpad/scripts/ftests/test_oops_prune.py 2009-08-07 12:46:37 +0000
3+++ lib/canonical/launchpad/scripts/ftests/test_oops_prune.py 2010-03-19 09:17:09 +0000
4@@ -17,6 +17,7 @@
5 import unittest
6
7 from pytz import UTC
8+import transaction
9
10 from canonical.config import config
11 from canonical.testing import LaunchpadZopelessLayer
12@@ -61,6 +62,10 @@
13 if not os.path.exists(config.error_reports.error_dir):
14 os.mkdir(config.error_reports.error_dir)
15
16+ # Need to commit or the changes are not visible on the slave.
17+ transaction.commit()
18+
19+
20 def tearDown(self):
21 shutil.rmtree(self.oops_dir)
22 shutil.rmtree(config.error_reports.error_dir)
23@@ -99,6 +104,10 @@
24 whiteboard=NULL
25 WHERE id=2
26 """)
27+
28+ # Need to commit or the changes are not visible on the slave.
29+ transaction.commit()
30+
31 self.failUnlessEqual(
32 set([
33 self.referenced_oops_code,
34
35=== modified file 'lib/canonical/launchpad/scripts/oops.py'
36--- lib/canonical/launchpad/scripts/oops.py 2009-06-25 05:30:52 +0000
37+++ lib/canonical/launchpad/scripts/oops.py 2010-03-19 09:17:09 +0000
38@@ -3,6 +3,8 @@
39
40 """Module docstring goes here."""
41
42+from __future__ import with_statement
43+
44 __metaclass__ = type
45
46 __all__ = [
47@@ -18,6 +20,7 @@
48
49 from canonical.database.sqlbase import cursor
50 from canonical.launchpad.webapp import errorlog
51+from canonical.launchpad.webapp.dbpolicy import SlaveOnlyDatabasePolicy
52 from canonical.launchpad.webapp.tales import FormattersAPI
53
54 def referenced_oops():
55@@ -51,18 +54,19 @@
56
57 referenced_codes = set()
58
59- cur = cursor()
60- cur.execute(query)
61- for content in (row[0] for row in cur.fetchall()):
62- found = False
63- for match in FormattersAPI._re_linkify.finditer(content):
64- if match.group('oops') is not None:
65- code_string = match.group('oopscode')
66- referenced_codes.add(code_string.upper())
67- found = True
68- assert found, \
69- 'PostgreSQL regexp matched content that Python regexp ' \
70- 'did not (%r)' % (content,)
71+ with SlaveOnlyDatabasePolicy():
72+ cur = cursor()
73+ cur.execute(query)
74+ for content in (row[0] for row in cur.fetchall()):
75+ found = False
76+ for match in FormattersAPI._re_linkify.finditer(content):
77+ if match.group('oops') is not None:
78+ code_string = match.group('oopscode')
79+ referenced_codes.add(code_string.upper())
80+ found = True
81+ assert found, \
82+ 'PostgreSQL regexp matched content that Python regexp ' \
83+ 'did not (%r)' % (content,)
84
85 return referenced_codes
86