make /live a cached cron job

remotes/1693176582716663532/tmp_refs/heads/watchparty
Aevann1 2022-09-22 04:33:45 +02:00
parent 59f7a7655b
commit 553218aaa5
2 changed files with 13 additions and 5 deletions

View File

@ -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()

View File

@ -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)
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])