new: Only update the cached index when displaying index page

pull/954/head
Raphaël Vinot 2024-10-09 18:29:15 +02:00
parent 844ebc6253
commit 43b23c23ac
3 changed files with 7 additions and 2 deletions

View File

@ -156,7 +156,6 @@ class CapturesIndex(Mapping): # type: ignore[type-arg]
@property
def cached_captures(self) -> set[str]:
self._quick_init()
return set(self.__cache.keys())
def __getitem__(self, uuid: str) -> CaptureCache:

View File

@ -190,6 +190,11 @@ class Lookyloo():
loglevel=get_config('generic', 'loglevel'))
return self._lacus
def update_cache_index(self) -> None:
'''Update the cache index with the latest captures'''
# NOTE: This call is moderately expensive as it iterates over all the non-archived captures
self._captures_index._quick_init()
def add_context(self, capture_uuid: str, /, urlnode_uuid: str, *, ressource_hash: str,
legitimate: bool, malicious: bool, details: dict[str, dict[str, str]]) -> None:
'''Adds context information to a capture or a URL node'''

View File

@ -1381,6 +1381,7 @@ def index_generic(show_hidden: bool=False, show_error: bool=True, category: str
cut_time = (datetime.now() - timedelta(**time_delta_on_index))
cut_time_with_tz = cut_time.replace(tzinfo=timezone.utc)
lookyloo.update_cache_index()
for cached in lookyloo.sorted_capture_cache(index_cut_time=cut_time):
if cut_time and cached.timestamp < cut_time_with_tz:
continue
@ -1548,7 +1549,7 @@ def ressource_by_hash(sha512: str) -> Response:
filename, body, mimetype = ressource
return send_file(body, as_attachment=True, download_name=filename)
return send_file(BytesIO(f'Unable to find {sha512}'.encode()), as_attachment=True, download_name='Hash unknown.')
return send_file(BytesIO(f'Unable to find {sha512}'.encode()), as_attachment=True, download_name='Unknown_Hash.txt')
# ################## Submit existing capture ##################