From 74457e5468bdbe15b65592e48800e56960b902f3 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Tue, 20 Dec 2022 04:26:23 +0200 Subject: [PATCH] rework stats a bit --- files/helpers/cron.py | 4 ++-- files/routes/static.py | 9 +++------ files/templates/stats.html | 6 +++--- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/files/helpers/cron.py b/files/helpers/cron.py index e2889caf4..82ca50b8e 100644 --- a/files/helpers/cron.py +++ b/files/helpers/cron.py @@ -42,8 +42,8 @@ def cron(every_5m, every_1h, every_1d, every_1mo): if every_1d: stats.generate_charts_task(SITE) _sub_inactive_purge_task() - cache.delete_memoized(route_static.stats_cached) - route_static.stats_cached() + stats = statshelper.stats(SITE_NAME) + cache.set(f'{SITE}_stats', stats) if every_1mo: if KOFI_LINK: _give_monthly_marseybux_task_kofi() diff --git a/files/routes/static.py b/files/routes/static.py index d0539fcb4..c776dac2c 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -84,12 +84,9 @@ def sidebar(v:Optional[User]): @app.get("/stats") @auth_required def participation_stats(v:User): - if v.client: return stats_cached() - return render_template("stats.html", v=v, title="Content Statistics", data=stats_cached()) - -@cache.memoize(timeout=864000) -def stats_cached(): - return statshelper.stats(SITE_NAME) + stats = cache.get(f'{SITE}_stats') or {} + if v.client: return stats + return render_template("stats.html", v=v, title="Content Statistics", data=stats) @app.get("/chart") def chart(): diff --git a/files/templates/stats.html b/files/templates/stats.html index ae196bdd9..3affe22f1 100644 --- a/files/templates/stats.html +++ b/files/templates/stats.html @@ -8,10 +8,10 @@ Value -{% for entry in data %} +{% for key, value in data.items() %} - {{entry}} - {{data[entry]}} + {{key}} + {{value}} {% endfor %}