mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-24 08:47:40 +00:00
Expire sessions generated by health checks quickly
The default expiration of sessions is 7 days. With healthchecks run every few seconds, we quickly have millions of anonymous sessions in Redis. Allow to define a custom expiration for some sessions and set a very short one for the monitoring requests.
This commit is contained in:
committed by
jcoux
co-authored by
jcoux
parent
3b1a0f4d8e
commit
d0afebfa4b
@@ -39,6 +39,9 @@ class RedisSessionStore(SessionStore):
|
||||
def save(self, session):
|
||||
key = self.build_key(session.sid)
|
||||
|
||||
# allow to set a custom expiration for a session
|
||||
# such as a very short one for monitoring requests
|
||||
expiration = session.expiration or self.expiration
|
||||
if _logger.isEnabledFor(logging.DEBUG):
|
||||
if session.uid:
|
||||
user_msg = "user '%s' (id: %s)" % (
|
||||
@@ -47,10 +50,10 @@ class RedisSessionStore(SessionStore):
|
||||
user_msg = "anonymous user"
|
||||
_logger.debug("saving session with key '%s' and "
|
||||
"expiration of %s seconds for %s",
|
||||
key, self.expiration, user_msg)
|
||||
key, expiration, user_msg)
|
||||
|
||||
if self.redis.set(key, json.dumps(dict(session))):
|
||||
return self.redis.expire(key, self.expiration)
|
||||
return self.redis.expire(key, expiration)
|
||||
|
||||
def delete(self, session):
|
||||
key = self.build_key(session.sid)
|
||||
|
||||
Reference in New Issue
Block a user