Merge lp:~jr.allen/unifield-server/us-2070-us-2059 into lp:unifield-server

Proposed by jftempo
Status: Merged
Merged at revision: 4105
Proposed branch: lp:~jr.allen/unifield-server/us-2070-us-2059
Merge into: lp:unifield-server
Diff against target: 60 lines (+15/-8)
1 file modified
bin/addons/sync_client/operations.py (+15/-8)
To merge this branch: bzr merge lp:~jr.allen/unifield-server/us-2070-us-2059
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+312491@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/addons/sync_client/operations.py'
2--- bin/addons/sync_client/operations.py 2016-11-23 10:29:08 +0000
3+++ bin/addons/sync_client/operations.py 2016-12-05 16:55:24 +0000
4@@ -38,11 +38,17 @@
5 if self._rl > 0:
6 return True
7
8+ # _rl has just gone to 0, so log the last message, which is the
9+ # rate limit notification. Be careful to log this into operations.event,
10+ # even if self is an operations.count. (US-2070)
11+ assert self._rl == 0
12+ oe = self.pool.get('operations.event')
13 vals = { 'kind': 'rate-limit',
14 'data': 'No more %s will be logged until next purge.' % self._rl_name
15 }
16 # Do not call self.create, because it calls us -> loop.
17- osv.osv.create(self, cr, uid, vals, context=context)
18+ osv.osv.create(oe, cr, uid, vals, context=context)
19+
20 return False
21
22 def create(self, cr, uid, vals, context=None):
23@@ -75,7 +81,7 @@
24 self._rl = self._rl_max
25 # SQL queries longer than this will be logged.
26 self.SLOW_QUERY = 10 # seconds
27- self._reset_slow_queries()
28+ self._slow_queries = {}
29
30 def create(self, cr, uid, vals, context=None):
31 """Override create in order to respect the rate limit."""
32@@ -87,9 +93,6 @@
33 tot, ct = self._slow_queries.get(q, (0, 0))
34 self._slow_queries[q] = (tot + delta, ct+1)
35
36- def _reset_slow_queries(self):
37- self._slow_queries = {}
38-
39 def _shorten(self, x):
40 if not isinstance(x, basestring):
41 return x
42@@ -153,12 +156,16 @@
43
44 self._rl = self._rl_max
45
46- for q in self._slow_queries:
47- tot, n = self._slow_queries[q]
48+ # Take a reference to it and reset it, so that any updates
49+ # that come in the background do not cause the dict to change while
50+ # iterating. (US-2059)
51+ sq = self._slow_queries
52+ self._slow_queries = {}
53+ for q in sq:
54+ tot, n = sq[q]
55 x = { 'count': n, 'average-latency': float(tot)/n, 'sql': q }
56 vals = { 'kind': 'slow-query', 'data': str(x) }
57 self.create(cr, uid, vals)
58- self._reset_slow_queries()
59
60 operations_event()
61

Subscribers

People subscribed via source and target branches

to all changes: