From 0c81f6b2187be1cf740d80282a84453199161cb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Mon, 1 Aug 2022 17:49:54 +0200 Subject: [PATCH] fix: Do not try to load archived captures in sorted_capture_cache --- lookyloo/lookyloo.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lookyloo/lookyloo.py b/lookyloo/lookyloo.py index b1fce40a..88d5f35f 100644 --- a/lookyloo/lookyloo.py +++ b/lookyloo/lookyloo.py @@ -317,8 +317,9 @@ class Lookyloo(): def update_tree_cache_info(self, process_id: int, classname: str) -> None: self.redis.hset('tree_cache', f'{process_id}|{classname}', str(self._captures_index.lru_cache_status())) - def sorted_capture_cache(self, capture_uuids: Optional[Iterable[str]]=None) -> List[CaptureCache]: - '''Get all the captures in the cache, sorted by timestamp (new -> old).''' + def sorted_capture_cache(self, capture_uuids: Optional[Iterable[str]]=None, cached_captures_only: bool=True) -> List[CaptureCache]: + '''Get all the captures in the cache, sorted by timestamp (new -> old). + By default, this method will only return the captures that are currently cached.''' if capture_uuids is None: # Sort all recent captures capture_uuids = self.redis.hkeys('lookup_dirs') @@ -326,6 +327,10 @@ class Lookyloo(): # No captures at all on the instance return [] + if cached_captures_only: + # Do not try to build pickles + capture_uuids = set(capture_uuids) & self._captures_index.cached_captures + all_cache: List[CaptureCache] = [self._captures_index[uuid] for uuid in capture_uuids if self.capture_cache(uuid)] all_cache.sort(key=operator.attrgetter('timestamp'), reverse=True) return all_cache