From fdf562bc32028cc0a2d3da1bad02a84da1e6a1d6 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Mon, 17 Jan 2022 08:06:31 +0100 Subject: [typing] add results.Timing --- searx/webapp.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'searx/webapp.py') diff --git a/searx/webapp.py b/searx/webapp.py index 905f53d1f..fc851d44e 100755 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -56,6 +56,7 @@ from searx import ( searx_debug, ) from searx.data import ENGINE_DESCRIPTIONS +from searx.results import Timing from searx.settings_defaults import OUTPUT_FORMATS from searx.settings_loader import get_default_settings_path from searx.exceptions import SearxParameterException @@ -234,7 +235,7 @@ class ExtendedRequest(flask.Request): form: Dict[str, str] start_time: float render_time: float - timings: List[dict] + timings: List[Timing] request = typing.cast(ExtendedRequest, flask.request) @@ -585,15 +586,14 @@ def post_request(response): 'render;dur=' + str(round(request.render_time * 1000, 3)), ] if len(request.timings) > 0: - timings = sorted(request.timings, key=lambda v: v['total']) + timings = sorted(request.timings, key=lambda t: t.total) timings_total = [ - 'total_' + str(i) + '_' + v['engine'] + ';dur=' + str(round(v['total'] * 1000, 3)) - for i, v in enumerate(timings) + 'total_' + str(i) + '_' + t.engine + ';dur=' + str(round(t.total * 1000, 3)) for i, t in enumerate(timings) ] timings_load = [ - 'load_' + str(i) + '_' + v['engine'] + ';dur=' + str(round(v['load'] * 1000, 3)) - for i, v in enumerate(timings) - if v.get('load') + 'load_' + str(i) + '_' + t.engine + ';dur=' + str(round(t.load * 1000, 3)) + for i, t in enumerate(timings) + if t.load ] timings_all = timings_all + timings_total + timings_load response.headers.add('Server-Timing', ', '.join(timings_all)) -- cgit v1.2.3