Skip to content

Commit e50b7cd

Browse files
author
Anthony Baxter
committed
Cache the session DB type.
If anyone can find a use-case for the session DB changing type during a run, you'll need to fix this. You should probably also seek professional help :) will forward-port to the trunk as well.
1 parent 21cb657 commit e50b7cd

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

roundup/backends/sessions.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#$Id: sessions.py,v 1.3 2002-09-10 00:11:50 richard Exp $
1+
#$Id: sessions.py,v 1.3.2.1 2003-06-24 06:27:55 anthonybaxter Exp $
22
'''
33
This module defines a very basic store that's used by the CGI interface
44
to store session information.
@@ -11,6 +11,9 @@ class Sessions:
1111
1212
Keys are session id strings, values are marshalled data.
1313
'''
14+
15+
_db_type = None
16+
1417
def __init__(self, config):
1518
self.config = config
1619
self.dir = config.DATABASE
@@ -24,8 +27,9 @@ def clear(self):
2427
elif os.path.exists(path+'.db'): # dbm appends .db
2528
os.remove(path+'.db')
2629

27-
def determine_db_type(self, path):
28-
''' determine which DB wrote the class file
30+
def cache_db_type(self, path):
31+
''' determine which DB wrote the class file, and cache it as a
32+
class attribute.
2933
'''
3034
db_type = ''
3135
if os.path.exists(path):
@@ -36,7 +40,7 @@ def determine_db_type(self, path):
3640
# if the path ends in '.db', it's a dbm database, whether
3741
# anydbm says it's dbhash or not!
3842
db_type = 'dbm'
39-
return db_type
43+
Sessions._db_type = db_type
4044

4145
def get(self, sessionid, value):
4246
db = self.opendb('c')
@@ -82,7 +86,10 @@ def opendb(self, mode):
8286
'''
8387
# figure the class db type
8488
path = os.path.join(os.getcwd(), self.dir, 'sessions')
85-
db_type = self.determine_db_type(path)
89+
if self._db_type is None:
90+
self.cache_db_type(path)
91+
92+
db_type = self._db_type
8693

8794
# new database? let anydbm pick the best dbm
8895
if not db_type:

0 commit comments

Comments
 (0)