diff options
author | Martin Fischer <martin@push-f.com> | 2022-01-17 08:06:31 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2022-01-17 11:42:48 +0100 |
commit | fdf562bc32028cc0a2d3da1bad02a84da1e6a1d6 (patch) | |
tree | b6095e5721ee680463703eb6a043d94fdcbd0853 /searx/results.py | |
parent | 1ed618222f17e205b684f6ef63cdaa470beb0dcb (diff) | |
download | searxng-fdf562bc32028cc0a2d3da1bad02a84da1e6a1d6.tar.gz searxng-fdf562bc32028cc0a2d3da1bad02a84da1e6a1d6.zip |
[typing] add results.Timing
Diffstat (limited to 'searx/results.py')
-rw-r--r-- | searx/results.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/searx/results.py b/searx/results.py index 6ab751c56..39e6e95d4 100644 --- a/searx/results.py +++ b/searx/results.py @@ -2,7 +2,9 @@ import re from collections import defaultdict from operator import itemgetter from threading import RLock +from typing import List, NamedTuple from urllib.parse import urlparse, unquote + from searx import logger from searx.engines import engines from searx.metrics import histogram_observe, counter_add, count_error @@ -137,6 +139,12 @@ def result_score(result): return sum((occurences * weight) / position for position in result['positions']) +class Timing(NamedTuple): + engine: str + total: float + load: float + + class ResultContainer: """docstring for ResultContainer""" @@ -169,7 +177,7 @@ class ResultContainer: self._closed = False self.paging = False self.unresponsive_engines = set() - self.timings = [] + self.timings: List[Timing] = [] self.redirect_url = None self.on_result = lambda _: True self._lock = RLock() @@ -405,13 +413,8 @@ class ResultContainer: if engines[engine_name].display_error_messages: self.unresponsive_engines.add((engine_name, error_type, error_message, suspended)) - def add_timing(self, engine_name, engine_time, page_load_time): - timing = { - 'engine': engines[engine_name].shortcut, - 'total': engine_time, - 'load': page_load_time, - } - self.timings.append(timing) + def add_timing(self, engine_name: str, engine_time: float, page_load_time: float): + self.timings.append(Timing(engine_name, total=engine_time, load=page_load_time)) def get_timings(self): return self.timings |