mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-24 02:08:36 +00:00
[MIG] session_redis: Migration to 16.0 (#392)
Co-authored-by: Hugo Santos <hugo.santos@factorlibre.com>
This commit is contained in:
co-authored by
GitHub
Hugo Santos
parent
dddd130e79
commit
988d4906bf
+9
-27
@@ -6,8 +6,8 @@ import os
|
|||||||
|
|
||||||
from .strtobool import strtobool
|
from .strtobool import strtobool
|
||||||
|
|
||||||
import odoo
|
|
||||||
from odoo import http
|
from odoo import http
|
||||||
|
from odoo.tools import config
|
||||||
from odoo.tools.func import lazy_property
|
from odoo.tools.func import lazy_property
|
||||||
|
|
||||||
from .session import RedisSessionStore
|
from .session import RedisSessionStore
|
||||||
@@ -52,22 +52,10 @@ def session_store(self):
|
|||||||
redis_client = redis.from_url(url)
|
redis_client = redis.from_url(url)
|
||||||
else:
|
else:
|
||||||
redis_client = redis.Redis(host=host, port=port, password=password)
|
redis_client = redis.Redis(host=host, port=port, password=password)
|
||||||
return RedisSessionStore(
|
return RedisSessionStore(redis=redis_client, prefix=prefix,
|
||||||
redis=redis_client,
|
expiration=expiration,
|
||||||
prefix=prefix,
|
anon_expiration=anon_expiration,
|
||||||
expiration=expiration,
|
session_class=http.Session)
|
||||||
anon_expiration=anon_expiration,
|
|
||||||
session_class=http.OpenERPSession,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def session_gc(session_store):
|
|
||||||
"""Do not garbage collect the sessions
|
|
||||||
|
|
||||||
Redis keys are automatically cleaned at the end of their
|
|
||||||
expiration.
|
|
||||||
"""
|
|
||||||
return
|
|
||||||
|
|
||||||
|
|
||||||
def purge_fs_sessions(path):
|
def purge_fs_sessions(path):
|
||||||
@@ -89,14 +77,8 @@ if is_true(os.environ.get("ODOO_SESSION_REDIS")):
|
|||||||
sentinel_port,
|
sentinel_port,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
_logger.debug(
|
_logger.debug("HTTP sessions stored in Redis with prefix '%s' on "
|
||||||
"HTTP sessions stored in Redis with prefix '%s' on " "%s:%s",
|
"%s:%s", prefix or '', host, port)
|
||||||
prefix or "",
|
http.Application.session_store = session_store
|
||||||
host,
|
|
||||||
port,
|
|
||||||
)
|
|
||||||
|
|
||||||
http.Root.session_store = session_store
|
|
||||||
http.session_gc = session_gc
|
|
||||||
# clean the existing sessions on the file system
|
# clean the existing sessions on the file system
|
||||||
purge_fs_sessions(odoo.tools.config.session_dir)
|
purge_fs_sessions(config.session_dir)
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from odoo.service import security
|
||||||
from odoo.tools._vendor.sessions import SessionStore
|
from odoo.tools._vendor.sessions import SessionStore
|
||||||
|
|
||||||
from . import json_encoding
|
from . import json_encoding
|
||||||
@@ -96,3 +97,18 @@ class RedisSessionStore(SessionStore):
|
|||||||
keys = self.redis.keys('%s*' % self.prefix)
|
keys = self.redis.keys('%s*' % self.prefix)
|
||||||
_logger.debug("a listing redis keys has been called")
|
_logger.debug("a listing redis keys has been called")
|
||||||
return [key[len(self.prefix):] for key in keys]
|
return [key[len(self.prefix):] for key in keys]
|
||||||
|
|
||||||
|
def rotate(self, session, env):
|
||||||
|
self.delete(session)
|
||||||
|
session.sid = self.generate_key()
|
||||||
|
if session.uid and env:
|
||||||
|
session.session_token = security.compute_session_token(session, env)
|
||||||
|
self.save(session)
|
||||||
|
|
||||||
|
def vacuum(self):
|
||||||
|
""" Do not garbage collect the sessions
|
||||||
|
|
||||||
|
Redis keys are automatically cleaned at the end of their
|
||||||
|
expiration.
|
||||||
|
"""
|
||||||
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user