From 182e7af1881222225857cbf3e4e65a725898c579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Fri, 28 Jul 2023 14:40:33 +0200 Subject: [PATCH] chg: Attempt to keep index up-to-date with cached captures --- lookyloo/capturecache.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lookyloo/capturecache.py b/lookyloo/capturecache.py index 2ad6267c..69e44a66 100644 --- a/lookyloo/capturecache.py +++ b/lookyloo/capturecache.py @@ -176,6 +176,7 @@ class CapturesIndex(Mapping): @property def cached_captures(self) -> Set[str]: + self._quick_init() return set(self.__cache.keys()) def __getitem__(self, uuid: str) -> CaptureCache: @@ -225,8 +226,14 @@ class CapturesIndex(Mapping): '''Initialize the cache with a list of UUIDs, with less back and forth with redis. Only get recent captures.''' p = self.redis.pipeline() - for directory in self.redis.hvals('lookup_dirs'): + has_new_cached_captures = False + for uuid, directory in self.redis.hscan_iter('lookup_dirs'): + if uuid in self.__cache: + continue + has_new_cached_captures = True p.hgetall(directory) + if not has_new_cached_captures: + return for cache in p.execute(): if not cache: continue