X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fipsilon.git;a=blobdiff_plain;f=ipsilon%2Futil%2Fsessions.py;fp=ipsilon%2Futil%2Fsessions.py;h=ef059d1fc67c0bb4dea717474d651438e0b78cef;hp=b870319abec1a0953570585350a1f49ea25d543b;hb=61de77fc7eae1f844944bd692d13bf27a1fda6fe;hpb=085d5b1a893b59af797dc530a5abdac1df118647 diff --git a/ipsilon/util/sessions.py b/ipsilon/util/sessions.py index b870319..ef059d1 100644 --- a/ipsilon/util/sessions.py +++ b/ipsilon/util/sessions.py @@ -10,12 +10,15 @@ except ImportError: import pickle -SESSION_COLUMNS = ['id', 'data', 'expiration_time'] +SESSION_TABLE = {'columns': ['id', 'data', 'expiration_time'], + 'primary_key': ('id', ), + 'indexes': [('expiration_time',)] + } class SessionStore(Store): def _initialize_schema(self): - q = self._query(self._db, 'sessions', SESSION_COLUMNS, + q = self._query(self._db, 'sessions', SESSION_TABLE, trans=False) q.create() @@ -44,12 +47,12 @@ class SqlSession(Session): cls._db = cls._store._db def _exists(self): - q = SqlQuery(self._db, 'sessions', SESSION_COLUMNS) + q = SqlQuery(self._db, 'sessions', SESSION_TABLE) result = q.select({'id': self.id}) return True if result.fetchone() else False def _load(self): - q = SqlQuery(self._db, 'sessions', SESSION_COLUMNS) + q = SqlQuery(self._db, 'sessions', SESSION_TABLE) result = q.select({'id': self.id}) r = result.fetchone() if r: @@ -59,7 +62,7 @@ class SqlSession(Session): def _save(self, expiration_time): q = None try: - q = SqlQuery(self._db, 'sessions', SESSION_COLUMNS, trans=True) + q = SqlQuery(self._db, 'sessions', SESSION_TABLE, trans=True) q.delete({'id': self.id}) data = pickle.dumps((self._data, expiration_time), self._proto) q.insert((self.id, base64.b64encode(data), expiration_time)) @@ -70,7 +73,7 @@ class SqlSession(Session): raise def _delete(self): - q = SqlQuery(self._db, 'sessions', SESSION_COLUMNS) + q = SqlQuery(self._db, 'sessions', SESSION_TABLE) q.delete({'id': self.id}) # copy what RamSession does for now