From 6ccfb1c1e1f2e3f6e3b662d900d62f71a540b8d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Wed, 25 Sep 2024 12:09:21 +0200 Subject: [PATCH] fix: Avoid exception awaiting index update --- lookyloo/indexing.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lookyloo/indexing.py b/lookyloo/indexing.py index fe005edb..621a4f34 100644 --- a/lookyloo/indexing.py +++ b/lookyloo/indexing.py @@ -462,6 +462,10 @@ class Indexing(): def get_captures_url_count(self, url: str) -> int: md5 = hashlib.md5(url.encode()).hexdigest() + if self.redis.type(f'urls|{md5}|captures') == 'set': # type: ignore[no-untyped-call] + # triggers the re-index soon. + self.redis.srem('indexed_urls', *self.redis.smembers(f'urls|{md5}|captures')) + return [] return self.redis.zcard(f'urls|{md5}|captures') def get_captures_hostname(self, hostname: str, most_recent_capture: datetime | None = None, @@ -481,6 +485,10 @@ class Indexing(): return self.redis.zrevrangebyscore(f'hostnames|{hostname}|captures', max_score, min_score, withscores=True) def get_captures_hostname_count(self, hostname: str) -> int: + if self.redis.type(f'hostnames|{hostname}|captures') == 'set': # type: ignore[no-untyped-call] + # triggers the re-index soon. + self.redis.srem('indexed_urls', *self.redis.smembers(f'hostnames|{hostname}|captures')) + return [] return self.redis.zcard(f'hostnames|{hostname}|captures') def get_capture_url_counter(self, capture_uuid: str, url: str) -> int: