From c9444fb9f79ec4c3fc4cd30038489aa25816261d Mon Sep 17 00:00:00 2001 From: celestix Date: Tue, 10 Sep 2024 04:22:21 +0530 Subject: [PATCH] fix: Leaderboard caching issue --- src/pwncore/routes/leaderboard.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/pwncore/routes/leaderboard.py b/src/pwncore/routes/leaderboard.py index 6cfc9ed..8a0059e 100644 --- a/src/pwncore/routes/leaderboard.py +++ b/src/pwncore/routes/leaderboard.py @@ -1,8 +1,9 @@ from __future__ import annotations +from json import dumps from time import monotonic -from fastapi import APIRouter, Request +from fastapi import APIRouter, Request, Response from tortoise.expressions import RawSQL, Q @@ -25,7 +26,7 @@ def __init__(self, period: float) -> None: self.data = [] async def _do_update(self): - self.data = ( + self.data = dumps(( await Team.all() .filter(Q(solved_problem__problem__visible=True) | Q(points__gte=0)) .annotate( @@ -38,8 +39,7 @@ async def _do_update(self): .group_by("id", "meta_team__name") .order_by("-tpoints") .values("name", "tpoints", "meta_team__name") - ) - + ), separators=(",", ":")).encode("utf-8") self.last_update = monotonic() async def get_lb(self, req: Request): @@ -57,4 +57,4 @@ async def get_lb(self, req: Request): @router.get("") async def fetch_leaderboard(req: Request): - return await gcache.get_lb(req) + return Response(content=await gcache.get_lb(req), media_type="application/json")