Skip to content

Commit 2fea4ca

Browse files
author
Andrey Lebedev
committed
cleaning old unused sessions only once per hour, not on every cgi request
1 parent 1e27183 commit 2fea4ca

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

CHANGES.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
This file contains the changes to the Roundup system over time. The entries
22
are given with the most recent entry first.
33

4-
2003-??-?? 0.6.0 (?)
4+
2003-??-?? 0.6.0
55
- better hyperlinking in web message texts
66
- support setting of properties on message and file through web and
77
email interface (thanks John Rouillard)
88
- allow additional control over the roundupdb email sending (explicit
99
cc addresses, different from address and different nosy list property)
1010
(thanks John Rouillard)
1111
- applied patch for nicer history display (sf feature 638280)
12-
12+
- cleaning old unused sessions only once per hour, not on every cgi
13+
request. It is greatly improves web interface performance, especially
14+
on trackers under high load
1315

1416
2003-??-?? 0.5.5
1517
- fixed rdbms searching by ID (sf bug 666615)
@@ -28,7 +30,7 @@ are given with the most recent entry first.
2830
(multipart/alternative, "fw" and content-type "name")
2931
- fire auditors and reactors in rdbms retire (thanks Sheila King)
3032
- better match for mailgw help "command" text
31-
- handle :add: better in cgi form parsing (sf bug 663235)
33+
- handle :add: better in cgi form parsing (sf bug 6632.35)
3234
- handle all-whitespace multilink values in forms (sf bug 663855)
3335
- fixed searching on date / interval fields (sf bug 658157)
3436
- fixed form elements names in search form to allow grouping and sorting

roundup/cgi/client.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: client.py,v 1.66 2003-01-11 23:52:28 richard Exp $
1+
# $Id: client.py,v 1.67 2003-01-13 22:14:00 kedder Exp $
22

33
__doc__ = """
44
WWW request handler (also used in the stand-alone server).
@@ -190,24 +190,34 @@ def inner_main(self):
190190
# everything else
191191
self.write(cgitb.html())
192192

193+
def clean_sessions(self):
194+
'''age sessions, remove when they haven't been used for a week.
195+
Do it only once an hour'''
196+
sessions = self.db.sessions
197+
last_clean = sessions.get('last_clean', 'last_use') or 0
198+
199+
week = 60*60*24*7
200+
hour = 60*60
201+
now = time.time()
202+
if now - last_clean > hour:
203+
# remove age sessions
204+
for sessid in sessions.list():
205+
print sessid
206+
interval = now - sessions.get(sessid, 'last_use')
207+
if interval > week:
208+
sessions.destroy(sessid)
209+
sessions.set('last_clean', last_use=time.time())
210+
193211
def determine_user(self):
194212
''' Determine who the user is
195213
'''
196214
# determine the uid to use
197215
self.opendb('admin')
198-
216+
# clean age sessions
217+
self.clean_sessions()
199218
# make sure we have the session Class
200219
sessions = self.db.sessions
201220

202-
# age sessions, remove when they haven't been used for a week
203-
# TODO: this shouldn't be done every access
204-
week = 60*60*24*7
205-
now = time.time()
206-
for sessid in sessions.list():
207-
interval = now - sessions.get(sessid, 'last_use')
208-
if interval > week:
209-
sessions.destroy(sessid)
210-
211221
# look up the user session cookie
212222
cookie = Cookie.Cookie(self.env.get('HTTP_COOKIE', ''))
213223
user = 'anonymous'

0 commit comments

Comments
 (0)