summaryrefslogtreecommitdiff
path: root/searx/webapp.py
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2021-05-06 09:39:52 +0200
committerAlexandre Flament <alex@al-f.net>2021-05-06 09:39:52 +0200
commitd12033e16602362f947c180560b26c71e6d523e9 (patch)
treee4a685c778faf172725bb7a1349673eaa0efdcce /searx/webapp.py
parent39eda78088bf81be768b2b7c347e2e159d34982c (diff)
downloadsearxng-d12033e16602362f947c180560b26c71e6d523e9.tar.gz
searxng-d12033e16602362f947c180560b26c71e6d523e9.zip
[mod] Server-Timing header: add render field
Add a "render" field to the Server-Timing header This field is the time spent in the searx.webapp.render function (Jinja2 rendering) See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Server-Timing
Diffstat (limited to 'searx/webapp.py')
-rwxr-xr-xsearx/webapp.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/searx/webapp.py b/searx/webapp.py
index dd1557c99..87c01fc9f 100755
--- a/searx/webapp.py
+++ b/searx/webapp.py
@@ -480,8 +480,11 @@ def render(template_name, override_theme=None, **kwargs):
for css in plugin.css_dependencies:
kwargs['styles'].add(css)
- return render_template(
+ start_time = default_timer()
+ result = render_template(
'{}/{}'.format(kwargs['theme'], template_name), **kwargs)
+ request.render_time += default_timer() - start_time
+ return result
def _get_ordered_categories():
@@ -498,6 +501,7 @@ def _get_ordered_categories():
@app.before_request
def pre_request():
request.start_time = default_timer()
+ request.render_time = 0
request.timings = []
request.errors = []
@@ -556,7 +560,8 @@ def add_default_headers(response):
@app.after_request
def post_request(response):
total_time = default_timer() - request.start_time
- timings_all = ['total;dur=' + str(round(total_time * 1000, 3))]
+ timings_all = ['total;dur=' + str(round(total_time * 1000, 3)),
+ 'render;dur=' + str(round(request.render_time * 1000, 3))]
if len(request.timings) > 0:
timings = sorted(request.timings, key=lambda v: v['total'])
timings_total = ['total_' + str(i) + '_' + v['engine'] +