From a5d6d4a7a6557749d087272d6461306e5828eb78 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 12 Jul 2022 20:12:44 +0100 Subject: [PATCH] Simplify css cache --- daemon.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/daemon.py b/daemon.py index ed08e6961..4beafca82 100644 --- a/daemon.py +++ b/daemon.py @@ -5780,6 +5780,7 @@ class PubServer(BaseHTTPRequestHandler): get_text_mode_banner(self.server.base_dir) self.server.iconsCache = {} self.server.fontsCache = {} + self.server.css_cache = {} self.server.show_publish_as_icon = \ get_config_param(self.server.base_dir, 'showPublishAsIcon') @@ -14321,18 +14322,23 @@ class PubServer(BaseHTTPRequestHandler): if '/' in path: path = path.split('/')[-1] path = base_dir + '/' + path - if os.path.isfile(path): + css = None + if self.server.css_cache.get(path): + css = self.server.css_cache[path] + elif os.path.isfile(path): tries = 0 while tries < 5: try: css = get_css(self.server.base_dir, path) if css: + self.server.css_cache[path] = css break except BaseException as ex: - print('EX: _get_style_sheet ' + + print('EX: _get_style_sheet ' + path + ' ' + str(tries) + ' ' + str(ex)) time.sleep(1) tries += 1 + if css: msg = css.encode('utf-8') msglen = len(msg) self._set_headers('text/css', msglen, @@ -21012,6 +21018,9 @@ def run_daemon(preferred_podcast_formats: [], # scan the theme directory for any svg files containing scripts assert not scan_themes_for_scripts(base_dir) + # caches css files + httpd.css_cache = {} + # load a list of dogwhistle words dogwhistles_filename = base_dir + '/accounts/dogwhistles.txt' if not os.path.isfile(dogwhistles_filename):