Skip to content

Commit

Permalink
Merge pull request #42 from celestix/leaderboard
Browse files Browse the repository at this point in the history
fix: leaderboard caching issue
  • Loading branch information
KreativeThinker authored Sep 11, 2024
2 parents fd43bb9 + c9444fb commit d3a8942
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/pwncore/routes/leaderboard.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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(
Expand All @@ -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):
Expand All @@ -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")

0 comments on commit d3a8942

Please sign in to comment.