changeset 8404:accddaeda449

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.
author John Rouillard <rouilj@ieee.org>
date Sat, 09 Aug 2025 20:30:51 -0400
parents c99e37d270b3
children 5eb470cbcc08
files roundup/backends/sessions_dbm.py
diffstat 1 files changed, 5 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/roundup/backends/sessions_dbm.py	Wed Jul 16 20:02:11 2025 -0400
+++ b/roundup/backends/sessions_dbm.py	Sat Aug 09 20:30:51 2025 -0400
@@ -203,15 +203,18 @@
         ''' Remove session records that haven't been used for a week. '''
         now = time.time()
         week = 60*60*24*7
+        a_week_ago = now - week
         for sessid in self.list():
             sess = self.get(sessid, '__timestamp', None)
             if sess is None:
                 self.updateTimestamp(sessid)
                 continue
-            interval = now - sess
-            if interval > week:
+            if a_week_ago > sess:
                 self.destroy(sessid)
 
+        run_time = time.time() - now
+        if run_time > 3:
+            self.log_warning("clean() took %.2fs", run_time)
 
 class Sessions(BasicDatabase):
     name = 'sessions'

Roundup Issue Tracker: http://roundup-tracker.org/