From 911fa5535aafd09fc0fde6935a62449be58da97f Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Mon, 16 Feb 2026 11:42:39 +0100 Subject: [PATCH] [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. --- session_redis/session.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/session_redis/session.py b/session_redis/session.py index da356479..70ff6875 100644 --- a/session_redis/session.py +++ b/session_redis/session.py @@ -176,17 +176,10 @@ def get_missing_session_identifiers( identifiers = set(identifiers) not_found = set() for partial_sid in identifiers: - try: - next( - self.redis.scan_iter( - match=f"{self.prefix}{partial_sid}*", - count=1, - ) - ) - except StopIteration: - # No matches found + key = f"session::{self.prefix}:{partial_sid}*" + match = self.redis.keys(pattern=key) + if not match: not_found.add(partial_sid) - return not_found def delete_from_identifiers(self, identifiers: builtins.list[PartialSid]):