add a developer warning for slow requests (#63)

This commit is contained in:
Lephe 2021-07-07 18:42:17 +02:00
parent c59e844852
commit f75f1618bc
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
5 changed files with 25 additions and 2 deletions

View File

@ -5,4 +5,4 @@ from app import app
@app.before_request
def request_time():
g.request_start_time = time()
g.request_time = lambda: "%.5fs" % (time() - g.request_start_time)
g.request_time = lambda: time() - g.request_start_time

View File

@ -85,3 +85,15 @@ header .form input[type="search"]:focus ~ a {
#spotlight a {
display: block;
}
#server-speed-warning {
background: var(--warn);
color: var(--warn-text);
text-align: center;
border-radius: 2px;
padding: 4px;
margin: 0 8px;
font-weight: bold;
text-shadow: 0 1px 1px rgba(0,0,0,.5);
}

View File

@ -2,7 +2,7 @@
<p>Planète Casio est un site communautaire non affilié à CASIO. Toute reproduction de Planète Casio, même partielle, est interdite.</p>
<p>Les programmes et autres publications présentes sur Planète Casio restent la propriété de leurs auteurs et peuvent être soumis à des licences ou des copyrights.</p>
{% if current_user.is_authenticated and current_user.priv('misc.dev-infos') %}
<p>Page générée en {{ g.request_time() }}</p>
<p>Page générée en {{ "%.3f" % g.request_time() }} secondes.</p>
{% endif %}
<p>Ceci est un environnement de test. Tout contenu peut être supprimé sans avertissement préalable.</p>
</footer>

View File

@ -11,3 +11,10 @@
<div id="spotlight">
<a href="#" class="button bg-error">Jeu du mois : février 2019</a>
</div>
{% if current_user.is_authenticated and current_user.priv('misc.dev-infos') %}
{% set reqtime = g.request_time() %}
{% if reqtime > V5Config.SLOW_REQUEST_THRESHOLD %}
<div id="server-speed-warning">Génération<br>{{ "%.3f" % reqtime }} s</div>
{% endif %}
{% endif %}

View File

@ -55,6 +55,10 @@ class DefaultConfig(object):
GLADOS_PORT = 5555
# Time before trigerring the necropost alert
NECROPOST_LIMIT = timedelta(days=31)
# Acceptable page loading time; longer generation is reported to devs. This
# is computed in the page header, so it doesn't account for most of the
# template generation.
SLOW_REQUEST_THRESHOLD = 0.400 # s
class V5Config(LocalConfig, DefaultConfig):