webapp: improve performance
authorHelmut Grohne <helmut@subdivi.de>
Wed, 29 Dec 2021 19:56:03 +0000 (20:56 +0100)
committerHelmut Grohne <helmut@subdivi.de>
Wed, 29 Dec 2021 19:56:03 +0000 (20:56 +0100)
html_response expects a str-generator, but when we call the render
method, we receive a plain str. It can be iterated - one character at a
time. That's what encode_and_buffer will do in this case. So better
stream all the time.

webapp.py

index 8f5d342..9993cb0 100755 (executable)
--- a/webapp.py
+++ b/webapp.py
@@ -100,7 +100,7 @@ class Application:
             elif endpoint == "index":
                 if not request.environ["PATH_INFO"]:
                     raise InternalRedirect("/")
-                return html_response(index_template.render(dict(urlroot="")))
+                return html_response(index_template.stream(dict(urlroot="")))
             elif endpoint == "source":
                 return self.show_source(args["package"])
             raise NotFound()
@@ -159,7 +159,7 @@ class Application:
                     (params["pid"],))
         params["issues"] = dict(cur.fetchall())
         cur.close()
-        return html_response(package_template.render(params))
+        return html_response(package_template.stream(params))
 
     def compute_comparison(self, pid1, pid2):
         """Compute a sequence of comparison objects ordered by the size of the
@@ -237,7 +237,7 @@ class Application:
                 raise NotFound()
         params = dict(function=function, hashvalue=hashvalue, entries=entries,
                       urlroot="../..")
-        return html_response(hash_template.render(params))
+        return html_response(hash_template.stream(params))
 
     def show_source(self, package):
         with contextlib.closing(self.db.cursor()) as cur:
@@ -256,7 +256,7 @@ class Application:
                 if not (oldentry and oldentry["savable"] >= size):
                     binpkgs[binary] = entry
         params = dict(source=package, packages=binpkgs, urlroot="..")
-        return html_response(source_template.render(params))
+        return html_response(source_template.stream(params))
 
 def main():
     parser = argparse.ArgumentParser()