Skip to content

Commit bd9c88a

Browse files
committed
precache in background (huge speed increase on startup)
1 parent a369f87 commit bd9c88a

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

handlers/admin/index.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ async def admin_index(request: Request) -> str:
2727
@admin_only
2828
async def admin_recalculate_ratings(request: Request) -> str:
2929
request.app.ctx.banner["text"] = "Rating recalculation in progress, stats may be inaccurate and the site may be slow"
30-
asyncio.create_task(recalculate_ratings(), name="Recalculate Ratings").add_done_callback(lambda _: reset_banner())
30+
request.app.create_task(recalculate_ratings(), name="Recalculate Ratings").add_done_callback(lambda _: reset_banner())
3131

3232
return response.json({"status": "ok"})
3333

@@ -36,7 +36,7 @@ async def admin_recalculate_ratings(request: Request) -> str:
3636
@admin_only
3737
async def admin_recalculate_sm5_ratings(request: Request) -> str:
3838
request.app.ctx.banner["text"] = "Rating recalculation in progress, stats may be inaccurate and the site may be slow"
39-
asyncio.create_task(recalculate_sm5_ratings(), name="Recalculate SM5 Ratings").add_done_callback(lambda _: reset_banner())
39+
request.app.create_task(recalculate_sm5_ratings(), name="Recalculate SM5 Ratings").add_done_callback(lambda _: reset_banner())
4040

4141
return response.json({"status": "ok"})
4242

@@ -45,7 +45,7 @@ async def admin_recalculate_sm5_ratings(request: Request) -> str:
4545
@admin_only
4646
async def admin_recalculate_lb_ratings(request: Request) -> str:
4747
request.app.ctx.banner["text"] = "Rating recalculation in progress, stats may be inaccurate and the site may be slow"
48-
asyncio.create_task(recalculate_laserball_ratings(), name="Recalculate Laserball Ratings").add_done_callback(lambda _: reset_banner())
48+
request.app.create_task(recalculate_laserball_ratings(), name="Recalculate Laserball Ratings").add_done_callback(lambda _: reset_banner())
4949

5050
return response.json({"status": "ok"})
5151

web.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ async def setup_app(app, loop) -> None:
110110
if "--debug" not in sys.argv:
111111
logger.info("Using cache")
112112
cachehelper.use_cache()
113-
await cachehelper.precache_all_functions()
113+
app.add_task(cachehelper.precache_all_functions())
114114
else:
115115
logger.info("Not using cache, --debug argument detected")
116116

0 commit comments

Comments
 (0)