From da3d1fe392ecccfed22c4703fb7f0e7846babc13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Fri, 5 Apr 2019 15:07:22 +0200 Subject: [PATCH] fix: Avoid loading the cache multiple times --- bin/start_website.py | 5 ++++- lookyloo/lookyloo.py | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bin/start_website.py b/bin/start_website.py index 27894481..214c2568 100755 --- a/bin/start_website.py +++ b/bin/start_website.py @@ -4,9 +4,12 @@ import time import signal from subprocess import Popen -from lookyloo.helpers import get_homedir, shutdown_requested, set_running, unset_running +from lookyloo.helpers import get_homedir, shutdown_requested, set_running, unset_running, get_socket_path + if __name__ == '__main__': + r = StrictRedis(unix_socket_path=get_socket_path('cache'), db=1) + r.delete('cache_loaded') website_dir = get_homedir() / 'website' Popen([str(website_dir / '3rdparty.sh')], cwd=website_dir) try: diff --git a/lookyloo/lookyloo.py b/lookyloo/lookyloo.py index d7c8a2f6..713955f2 100644 --- a/lookyloo/lookyloo.py +++ b/lookyloo/lookyloo.py @@ -37,7 +37,8 @@ class Lookyloo(): if not self.scrape_dir.exists(): self.scrape_dir.mkdir(parents=True, exist_ok=True) - self._init_existing_dumps() + if not self.redis.exists('cache_loaded'): + self._init_existing_dumps() # Try to reach sanejs self.sanejs = SaneJS() @@ -68,7 +69,7 @@ class Lookyloo(): cache = {'uuid': uuid, 'title': title} if (report_dir / 'no_index').exists(): # If the folders claims anonymity cache['no_index'] = 1 - if uuid and not self.redis.hexists('lookup_dirs', uuid): + if uuid and not self.redis.exists(str(report_dir)): self.redis.hmset(str(report_dir), cache) self.redis.hset('lookup_dirs', uuid, str(report_dir)) @@ -79,7 +80,9 @@ class Lookyloo(): def _init_existing_dumps(self): for report_dir in self.report_dirs: - self._set_report_cache(report_dir) + if report_dir.exists(): + self._set_report_cache(report_dir) + self.redis.set('cache_loaded', 1) @property def report_dirs(self):