Skip to content

[18.0][FIX] session_redis: backport device session methods - #530

Draft
guewen wants to merge 3 commits into
camptocamp:18.0from
qoqa:18.0-backport-session-redis
Draft

guewen wants to merge 3 commits into
camptocamp:18.0from
qoqa:18.0-backport-session-redis

Conversation

@guewen

@guewen guewen commented Sep 7, 2026

Copy link
Copy Markdown

Backport from #499
Partial cherry-pick of commit 750bc4d

The methods have been added on the SessionStore in odoo 18.0 through
odoo/odoo@80224f3

Also applied the performance fix done in qoqa@911fa55

aisopuro and others added 3 commits September 7, 2026 10:50
Backport from camptocamp#499
Partial cherry-pick of commit camptocamp@750bc4d

The methods have been added on the SessionStore in odoo 18.0 through
odoo/odoo@80224f3
On the cloud platform of Camptocamp, a shared redis is used to store the
sessions of the different projects -> the number of keys is huge, and
using an iterative match kills the performance because of the networking
overhead.

We switch to using redis.key(pattern), and since the pattern typically
has a leading string which will allow redis to find the correct bucket,
the performance should be good.
* `generate_key()` produces a key of 40 chars, use `_sha1_re` to find
  them rather than _session_identifier_re that expects 42 chars
* in `get_missing_session_identifiers`, self.prefix already contains
  the `session:` and final `:` parts. A key looks like "session:0424149fe72a3e5ae5bd4e3789e80401230ce219"
  or "session:foo:0424149fe72a3e5ae5bd4e3789e80401230ce219"

Tested on a local instance and in ipython

    In [11]: import redis

    In [12]: from odoo.addons.session_redis.http import RedisSessionStore

    In [13]: redis_client = redis.Redis()

    In [14]: store = RedisSessionStore(
        ...:         redis=redis_client, session_class=http.Session)

    In [15]: store
    Out[15]: <odoo.addons.session_redis.session.RedisSessionStore at 0x7f415cd255b0>

    In [16]: store.get_missing_session_identifiers(['0424149fe72a3e5ae5bd4e3789e80401230ce219'])
    # the key exists so no result as expected
    Out[16]: set()

    In [17]: store.get_missing_session_identifiers(['0424149fe72a3e5ae5bd4e3789e80401230ce218'])
    # the key does not exist so result as expected
    Out[17]: {'0424149fe72a3e5ae5bd4e3789e80401230ce218'}

    In [18]: store.delete_from_identifiers(['0424149fe72a3e5ae5bd4e3789e80401230ce218'])
    # no error on missing identifier

    In [19]: store.delete_from_identifiers(['0424149fe72a3e5ae5bd4e3789e80401230ce219'])
    # checked removed in redis
@guewen
guewen force-pushed the 18.0-backport-session-redis branch from 5d78318 to 9425c1c Compare September 7, 2026 09:02
Comment thread session_redis/session.py
identifiers = set(identifiers)
not_found = set()
for partial_sid in identifiers:
key = f"{self.prefix}{partial_sid}*"

@guewen guewen Sep 7, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In branch 19.0, the key is set as f"session::{self.prefix}:{partial_sid}*", which does not look correct to me? because self.prefix already contains the session: and final : parts. A key looks like "session:0424149fe72a3e5ae5bd4e3789e80401230ce219" or "session::foo:0424149fe72a3e5ae5bd4e3789e80401230ce219".

Comment thread session_redis/session.py
# Avoid removing a session if it does not match an identifier.
# See this same comment in
# odoo.http.FileSessionStore.delete_from_identifiers.
if not _sha1_re.match(identifier):

@guewen guewen Sep 7, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To minimize the change, instead of changing the way of generation session sid as done in 19.0, I changed the check to use the pattern that matches the sid generated by SessionStore (40 chars).

@guewen guewen mentioned this pull request Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants