Conversation
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
force-pushed
the
18.0-backport-session-redis
branch
from
September 7, 2026 09:02
5d78318 to
9425c1c
Compare
guewen
commented
Sep 7, 2026
| identifiers = set(identifiers) | ||
| not_found = set() | ||
| for partial_sid in identifiers: | ||
| key = f"{self.prefix}{partial_sid}*" |
Author
There was a problem hiding this comment.
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".
guewen
commented
Sep 7, 2026
| # 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): |
Author
There was a problem hiding this comment.
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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