perf: cache routes

This commit is contained in:
Ayo Ayco 2024-05-20 16:33:56 +02:00
parent 5d0eec7a5c
commit 4b6c7d09fe

View file

@ -62,10 +62,12 @@ def thread(id):
return '<h1>Not Found</h1><p>¯\_(ツ)_/¯</p><a href="/">go home</a>', 404 return '<h1>Not Found</h1><p>¯\_(ツ)_/¯</p><a href="/">go home</a>', 404
@threads.route('/api') @threads.route('/api')
@cache.cached(timeout=300)
async def api(): async def api():
return await fetch_statuses(); return await fetch_statuses();
@threads.route('/api/<path:id>') @threads.route('/api/<path:id>')
@cache.cached(timeout=300)
def api_thread(id): def api_thread(id):
return fetch_thread(id) return fetch_thread(id)
@ -80,7 +82,6 @@ async def get(url, session):
def get_status_url(ser, id): def get_status_url(ser, id):
return f'{ser}/api/v1/statuses/{id}' return f'{ser}/api/v1/statuses/{id}'
# @cache.cached(timeout=300)
async def fetch_statuses(): async def fetch_statuses():
statuses = [] statuses = []
urls = [get_status_url(server, id) for id in thread_ids] urls = [get_status_url(server, id) for id in thread_ids]
@ -91,7 +92,6 @@ async def fetch_statuses():
except: except:
return [] return []
@cache.cached(timeout=300)
def fetch_thread(id): def fetch_thread(id):
status = requests.get(server + '/api/v1/statuses/' + id ).json() status = requests.get(server + '/api/v1/statuses/' + id ).json()
status = clean_status(status) status = clean_status(status)