Mercurial > p > roundup > code
comparison roundup/cgi/client.py @ 1694:03170eb33b82 maint-0.5
only clean sessions once per hour (backport from trunk)
| author | Anthony Baxter <anthonybaxter@users.sourceforge.net> |
|---|---|
| date | Tue, 24 Jun 2003 04:23:35 +0000 |
| parents | b6621f8bd496 |
| children | 25ffe34775f1 |
comparison
equal
deleted
inserted
replaced
| 1691:d6177306d010 | 1694:03170eb33b82 |
|---|---|
| 1 # $Id: client.py,v 1.65.2.10 2003-06-24 03:33:56 richard Exp $ | 1 # $Id: client.py,v 1.65.2.11 2003-06-24 04:23:35 anthonybaxter Exp $ |
| 2 | 2 |
| 3 __doc__ = """ | 3 __doc__ = """ |
| 4 WWW request handler (also used in the stand-alone server). | 4 WWW request handler (also used in the stand-alone server). |
| 5 """ | 5 """ |
| 6 | 6 |
| 213 ''' Determine who the user is | 213 ''' Determine who the user is |
| 214 ''' | 214 ''' |
| 215 # determine the uid to use | 215 # determine the uid to use |
| 216 self.opendb('admin') | 216 self.opendb('admin') |
| 217 | 217 |
| 218 self.clean_sessions() | |
| 219 | |
| 218 # make sure we have the session Class | 220 # make sure we have the session Class |
| 219 sessions = self.db.sessions | 221 sessions = self.db.sessions |
| 220 | |
| 221 # age sessions, remove when they haven't been used for a week | |
| 222 # TODO: this shouldn't be done every access | |
| 223 week = 60*60*24*7 | |
| 224 now = time.time() | |
| 225 for sessid in sessions.list(): | |
| 226 interval = now - sessions.get(sessid, 'last_use') | |
| 227 if interval > week: | |
| 228 sessions.destroy(sessid) | |
| 229 | 222 |
| 230 # look up the user session cookie | 223 # look up the user session cookie |
| 231 cookie = Cookie.Cookie(self.env.get('HTTP_COOKIE', '')) | 224 cookie = Cookie.Cookie(self.env.get('HTTP_COOKIE', '')) |
| 232 user = 'anonymous' | 225 user = 'anonymous' |
| 233 | 226 |
| 259 else: | 252 else: |
| 260 self.user = user | 253 self.user = user |
| 261 | 254 |
| 262 # reopen the database as the correct user | 255 # reopen the database as the correct user |
| 263 self.opendb(self.user) | 256 self.opendb(self.user) |
| 257 | |
| 258 def clean_sessions(self): | |
| 259 ''' Age sessions, remove when they haven't been used for a week. | |
| 260 | |
| 261 Do it only once an hour. | |
| 262 ''' | |
| 263 sessions = self.db.sessions | |
| 264 last_clean = sessions.get('last_clean', 'last_use') or 0 | |
| 265 | |
| 266 week = 60*60*24*7 | |
| 267 hour = 60*60 | |
| 268 now = time.time() | |
| 269 if now - last_clean > hour: | |
| 270 # remove aged sessions | |
| 271 for sessid in sessions.list(): | |
| 272 interval = now - sessions.get(sessid, 'last_use') | |
| 273 if interval > week: | |
| 274 sessions.destroy(sessid) | |
| 275 sessions.set('last_clean', last_use=time.time()) | |
| 264 | 276 |
| 265 def determine_context(self, dre=re.compile(r'([^\d]+)(\d+)')): | 277 def determine_context(self, dre=re.compile(r'([^\d]+)(\d+)')): |
| 266 ''' Determine the context of this page from the URL: | 278 ''' Determine the context of this page from the URL: |
| 267 | 279 |
| 268 The URL path after the instance identifier is examined. The path | 280 The URL path after the instance identifier is examined. The path |
