From 52e358a48d5fc94bda751bc6aa70dd3b25f4ddb3 Mon Sep 17 00:00:00 2001 From: Florian Festi Date: Sun, 5 Feb 2023 16:14:14 +0100 Subject: [PATCH] Gallery: Use cache --- scripts/boxesserver | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/scripts/boxesserver b/scripts/boxesserver index 04c6d9d..f4ccf40 100755 --- a/scripts/boxesserver +++ b/scripts/boxesserver @@ -481,11 +481,16 @@ class BServer: def serveGallery(self, environ, start_response, lang): _ = lang.gettext lang_name = lang.info().get('language', None) + + start_response("200 OK", [('Content-type', "text/html; charset=utf-8")]) + + if ("Gallery", lang_name) in self._cache: + return self._cache[("Gallery", lang_name)] + langparam = "" if lang_name: langparam = "?language=" + lang_name - start_response("200 OK", [('Content-type', "text/html; charset=utf-8")]) result = [f""" {self.genHTMLStart(lang)} @@ -528,8 +533,9 @@ class BServer: """ ) - return (s.encode("utf-8") for s in result) - + self._cache[("Gallery", lang_name)] = [s.encode("utf-8") for s in result] + return self._cache[("Gallery", lang_name)] + def serve(self, environ, start_response): # serve favicon from static for generated SVGs if environ["PATH_INFO"] == "favicon.ico":