summaryrefslogtreecommitdiffstats
path: root/pykolab
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2020-10-02 16:05:05 +0200
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2022-02-03 11:30:18 +0100
commit1a925794a9a67c94165b93d087a9a70c2076eb82 (patch)
treeb28e3c2ab1bc07f694f293923d6d13fc0693d22e /pykolab
parentd2f1fed940ba610230b8e78a6748d43c90ba8002 (diff)
downloadpykolab-1a925794a9a67c94165b93d087a9a70c2076eb82.tar.gz
Shorten the window of entries considered valid still
Diffstat (limited to 'pykolab')
-rw-r--r--pykolab/auth/ldap/auth_cache.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/pykolab/auth/ldap/auth_cache.py b/pykolab/auth/ldap/auth_cache.py
index dcf8c23..41ef438 100644
--- a/pykolab/auth/ldap/auth_cache.py
+++ b/pykolab/auth/ldap/auth_cache.py
@@ -120,13 +120,21 @@ def get_entry(key):
finally:
_entries = db.query(Entry).filter_by(key=key).all()
- if len(_entries) != 1:
+ __entries = []
+
+ for __entry in _entries:
+ if __entry.last_change <= datetime.datetime.now() - datetime.timedelta(0, 7200):
+ continue
+
+ __entries.append(__entry)
+
+ if len(__entries) != 1:
return None
- log.debug("Entry found: %r" % (_entries[0].__dict__))
- log.debug("Returning: %r" % (_entries[0].value))
+ log.debug("Entry found: %r" % (__entries[0].__dict__))
+ log.debug("Returning: %r" % (__entries[0].value))
- return _entries[0].value.encode('utf-8', 'latin1')
+ return __entries[0].value.encode('utf-8', 'latin1')
def set_entry(key, value):
@@ -168,7 +176,7 @@ def purge_entries():
try:
db.query(Entry).filter(
- Entry.last_change <= (datetime.datetime.now() - datetime.timedelta(1))
+ Entry.last_change <= (datetime.datetime.now() - datetime.timedelta(0, 7200))
).delete()
db.commit()