feat: Improve search engines loading time info

This commit is contained in:
Myzel394 2024-01-07 21:11:32 +01:00
parent d4dfec3f3e
commit 89909f06af
No known key found for this signature in database
GPG key ID: 79CC92F37B3E1A2B
2 changed files with 15 additions and 14 deletions

View file

@ -35,21 +35,16 @@
<div id="sidebar">
{%- if number_of_results != '0' -%}
<p id="result_count">
<small>{{ _('Number of results') }}: {{ number_of_results }}</small>
</p>
<details>
<summary>
<small>Longest loading time: {{ longest_loading_time.load }} from {{ longest_loading_time.engine }}</small>
<small id="result_count">{{ _('Number of results') }}: {{ number_of_results }}</small>
<small>{{ longest_load_time_formatted }}</small>
</summary>
<div>
<ul>
{% for timing in loading_times %}
<li>
<small>{{ timing.load }} from {{ timing.engine }}</small>
</li>
{% endfor %}
</ul>
<ul>
{% for engine, timing in loading_times %}
<li>{{ engine }}: {{ timing }}</li>
{% endfor %}
</ul>
</details>
{%- endif -%}

View file

@ -794,8 +794,14 @@ def search():
fallback=request.preferences.get_value("language")
),
timeout_limit = request.form.get('timeout_limit', None),
longest_loading_time = longest_loading_time,
loading_times = timings,
longest_load_time_formatted = gettext("Took {seconds} second(s)")
.format(seconds="{:.2f}".format(longest_loading_time[1])),
# List of tuples of (engine, load time); Displayed in the sidebar
# Sorted by load time, descending
loading_times = sorted((
(timing.engine, "{:.2f}".format(timing.load))
for timing in timings
), key=lambda x: x[1], reverse=True),
# fmt: on
)