Skip to content

Commit 7aa071d

Browse files
committed
fix: perf improvement for session clean() and warning added
Replaced a subtraction and comparison operation an inner loop with a comparison against a threhold. This mimics the session_rdbms code that uses a constant value for the timestamp threshold. Also added a log warning messge if clean() takes more than 3 seconds. It took me a while to track down the cause of an increasing delay in CGI response. Turns out it was cleaning the dbm otks database with 1.5k entries.
1 parent 292dabf commit 7aa071d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

roundup/backends/sessions_dbm.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,15 +203,18 @@ def clean(self):
203203
''' Remove session records that haven't been used for a week. '''
204204
now = time.time()
205205
week = 60*60*24*7
206+
a_week_ago = now - week
206207
for sessid in self.list():
207208
sess = self.get(sessid, '__timestamp', None)
208209
if sess is None:
209210
self.updateTimestamp(sessid)
210211
continue
211-
interval = now - sess
212-
if interval > week:
212+
if a_week_ago > sess:
213213
self.destroy(sessid)
214214

215+
run_time = time.time() - now
216+
if run_time > 3:
217+
self.log_warning("clean() took %.2fs", run_time)
215218

216219
class Sessions(BasicDatabase):
217220
name = 'sessions'

0 commit comments

Comments
 (0)