[PERF] fix performance hit

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.
This commit is contained in:
Alexandre Fayolle
2026-02-16 11:42:39 +01:00
parent 9838963ea4
commit 911fa5535a
+3 -10
View File
@@ -176,17 +176,10 @@ class RedisSessionStore(SessionStore):
identifiers = set(identifiers) identifiers = set(identifiers)
not_found = set() not_found = set()
for partial_sid in identifiers: for partial_sid in identifiers:
try: key = f"session::{self.prefix}:{partial_sid}*"
next( match = self.redis.keys(pattern=key)
self.redis.scan_iter( if not match:
match=f"{self.prefix}{partial_sid}*",
count=1,
)
)
except StopIteration:
# No matches found
not_found.add(partial_sid) not_found.add(partial_sid)
return not_found return not_found
def delete_from_identifiers(self, identifiers: builtins.list[PartialSid]): def delete_from_identifiers(self, identifiers: builtins.list[PartialSid]):