Skip to content

Commit 36a54f0

Browse files
author
Richard Jones
committed
reduced frequency of session timestamp update
1 parent 75a99b9 commit 36a54f0

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Fixed:
1616
- escape *all* uses of "schema" in mysql backend (sf bug 1472120)
1717
- responses to user rego email (sf bug 1470254)
1818
- dangling connections in session handling (sf bug 1463359)
19+
- reduced frequency of session timestamp update
1920

2021

2122
2006-03-03 1.1.1

roundup/backends/sessions_dbm.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#$Id: sessions_dbm.py,v 1.5 2004-03-31 23:08:38 richard Exp $
1+
#$Id: sessions_dbm.py,v 1.6 2006-04-27 04:03:11 richard Exp $
22
"""This module defines a very basic store that's used by the CGI interface
33
to store session and one-time-key information.
44
@@ -131,7 +131,11 @@ def close(self):
131131
pass
132132

133133
def updateTimestamp(self, sessid):
134-
self.set(sessid, __timestamp=time.time())
134+
''' don't update every hit - once a minute should be OK '''
135+
sess = self.get(sessid, '__timestamp', None)
136+
now = time.time()
137+
if sess is None or now > sess + 60:
138+
self.set(sessid, __timestamp=now)
135139

136140
def clean(self, now):
137141
"""Age sessions, remove when they haven't been used for a week.

roundup/backends/sessions_rdbms.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#$Id: sessions_rdbms.py,v 1.3 2004-05-02 23:16:05 richard Exp $
1+
#$Id: sessions_rdbms.py,v 1.4 2006-04-27 04:03:11 richard Exp $
22
"""This module defines a very basic store that's used by the CGI interface
33
to store session and one-time-key information.
44
@@ -77,9 +77,12 @@ def destroy(self, infoid):
7777
self.name, self.db.arg), (infoid,))
7878

7979
def updateTimestamp(self, infoid):
80-
self.cursor.execute('update %ss set %s_time=%s where %s_key=%s'%(
81-
self.name, self.name, self.db.arg, self.name, self.db.arg),
82-
(time.time(), infoid))
80+
''' don't update every hit - once a minute should be OK '''
81+
now = time.time()
82+
self.cursor.execute('''update %ss set %s_time=%s where %s_key=%s
83+
and %s_time < %s'''%(self.name, self.name, self.db.arg,
84+
self.name, self.db.arg, self.name, self.db.arg),
85+
(now, infoid, now-60))
8386

8487
def clean(self, now):
8588
"""Age sessions, remove when they haven't been used for a week.

roundup/cgi/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: client.py,v 1.224 2006-04-27 03:48:41 richard Exp $
1+
# $Id: client.py,v 1.225 2006-04-27 04:03:11 richard Exp $
22

33
"""WWW request handler (also used in the stand-alone server).
44
"""
@@ -466,8 +466,8 @@ def determine_user(self):
466466
try:
467467
# update the lifetime datestamp
468468
sessions.updateTimestamp(self.session)
469-
user = sessions.get(self.session, 'user')
470469
self.db.commit()
470+
user = sessions.get(self.session, 'user')
471471
except KeyError:
472472
# not valid, ignore id
473473
pass

0 commit comments

Comments
 (0)