From 49aa5edc9688694f78e24a8871fed521a1d8abdd Mon Sep 17 00:00:00 2001 From: MingxuanGame Date: Thu, 21 Aug 2025 09:07:45 +0000 Subject: [PATCH] fix(statistics): fix `rank_history` use country rank --- app/database/statistics.py | 39 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/app/database/statistics.py b/app/database/statistics.py index 749f6fb..be1f762 100644 --- a/app/database/statistics.py +++ b/app/database/statistics.py @@ -163,24 +163,25 @@ async def get_rank( if rank is None: return None - today = datetime.now(UTC).date() - rank_history = ( - await session.exec( - select(RankHistory).where( - RankHistory.user_id == statistics.user_id, - RankHistory.mode == statistics.mode, - RankHistory.date == today, + if country is None: + today = datetime.now(UTC).date() + rank_history = ( + await session.exec( + select(RankHistory).where( + RankHistory.user_id == statistics.user_id, + RankHistory.mode == statistics.mode, + RankHistory.date == today, + ) ) - ) - ).first() - if rank_history is None: - rank_history = RankHistory( - user_id=statistics.user_id, - mode=statistics.mode, - date=today, - rank=rank, - ) - session.add(rank_history) - else: - rank_history.rank = rank + ).first() + if rank_history is None: + rank_history = RankHistory( + user_id=statistics.user_id, + mode=statistics.mode, + date=today, + rank=rank, + ) + session.add(rank_history) + else: + rank_history.rank = rank return rank