From 553218aaa5a9f3df8968b79c55b3e2df5a52849e Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Thu, 22 Sep 2022 04:33:45 +0200 Subject: [PATCH] make /live a cached cron job --- files/helpers/cron.py | 2 ++ files/routes/static.py | 16 +++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/files/helpers/cron.py b/files/helpers/cron.py index 5b22796ea..c5393f5d2 100644 --- a/files/helpers/cron.py +++ b/files/helpers/cron.py @@ -39,6 +39,8 @@ def cron(every_5m, every_1h, every_1d, every_1mo): stats.generate_charts_task(SITE) route_static.stats_cached() sub_inactive_purge_task() + if SITE_NAME == 'PCM': + route_static.live_cached() if every_1mo: if KOFI_LINK: give_monthly_marseybux_task_kofi() diff --git a/files/routes/static.py b/files/routes/static.py index b1ef00c2c..54dfb0c03 100644 --- a/files/routes/static.py +++ b/files/routes/static.py @@ -466,10 +466,8 @@ if SITE_NAME == 'PCM': live_thumb_regex = re.compile('\{"thumbnail":\{"thumbnails":\[\{"url":"(.*?)"', flags=re.A) offline_regex = re.compile('","title":"(.*?)".*?"width":48,"height":48\},\{"url":"(.*?)"', flags=re.A) - @app.get('/live') - @app.get('/logged_out/live') - @auth_desired_with_logingate - def live(v): + @cache.memoize(timeout=86400) + def live_cached(): live = [] offline = [] for x in streamers: @@ -489,4 +487,12 @@ if SITE_NAME == 'PCM': try: offline.append((req.url, y.group(2), y.group(1))) except: print(x) - return render_template(f'live.html', v=v, live=live, offline=offline) \ No newline at end of file + live = sorted(live, key=lambda x: x[4], reverse=True) + + return live, offline + + @app.get('/live') + @app.get('/logged_out/live') + @auth_desired_with_logingate + def live(v): + return render_template(f'live.html', v=v, live=live_cached()[0], offline=live_cached()[1]) \ No newline at end of file