From: Patrick Uiterwijk Date: Fri, 4 Sep 2015 16:05:33 +0000 (+0200) Subject: Implement cleeanup for TranStore X-Git-Tag: v1.1.0~8 X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fipsilon.git;a=commitdiff_plain;h=2b17119bb97eba45030d18f590624c2b2a9f257e Implement cleeanup for TranStore Signed-off-by: Patrick Uiterwijk Reviewed-by: Rob Crittenden --- diff --git a/ipsilon/util/data.py b/ipsilon/util/data.py index 3f4ccff..52fde62 100644 --- a/ipsilon/util/data.py +++ b/ipsilon/util/data.py @@ -740,9 +740,10 @@ class TranStore(Store): def __init__(self, path=None): super(TranStore, self).__init__('transactions.db') + self.table = 'transactions' def _initialize_schema(self): - q = self._query(self._db, 'transactions', UNIQUE_DATA_TABLE, + q = self._query(self._db, self.table, UNIQUE_DATA_TABLE, trans=False) q.create() q._con.close() # pylint: disable=protected-access @@ -751,7 +752,7 @@ class TranStore(Store): if old_version == 1: # In schema version 2, we added indexes and primary keys # pylint: disable=protected-access - table = self._query(self._db, 'transactions', UNIQUE_DATA_TABLE, + table = self._query(self._db, self.table, UNIQUE_DATA_TABLE, trans=False)._table self._db.add_constraint(table.primary_key) for index in table.indexes: @@ -760,6 +761,17 @@ class TranStore(Store): else: raise NotImplementedError() + def _cleanup(self): + # pylint: disable=protected-access + table = SqlQuery(self._db, self.table, UNIQUE_DATA_TABLE)._table + in_one_hour = datetime.datetime.now() - datetime.timedelta(hours=1) + sel = select([table.columns.uuid]). \ + where(and_(table.c.name == 'origintime', + table.c.value <= in_one_hour)) + # pylint: disable=no-value-for-parameter + d = table.delete().where(table.c.uuid.in_(sel)) + return d.execute().rowcount + class SAML2SessionStore(Store):