From 8b6e91f76c9b3aff704a12d21195979fdd7fe745 Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Thu, 4 Jun 2020 16:54:45 -0400 Subject: [PATCH] Scoreboard optimizations (#1476) * Add speed improvements for /api/v1/scoreboard/top/ * Update CHANGELOG * Fix typo * Switch back to processing solves and awards seperately * Fix typo --- CTFd/api/v1/scoreboard.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/CTFd/api/v1/scoreboard.py b/CTFd/api/v1/scoreboard.py index 4314d71e..f8140b9f 100644 --- a/CTFd/api/v1/scoreboard.py +++ b/CTFd/api/v1/scoreboard.py @@ -122,7 +122,6 @@ class ScoreboardDetail(Resource): awards = awards.all() # Build a mapping of accounts to their solves and awards - solves = solves + awards solves_mapper = defaultdict(list) for solve in solves: solves_mapper[solve.account_id].append( @@ -136,6 +135,18 @@ class ScoreboardDetail(Resource): } ) + for award in awards: + solves_mapper[award.account_id].append( + { + "challenge_id": None, + "account_id": award.account_id, + "team_id": award.team_id, + "user_id": award.user_id, + "value": award.value, + "date": isoformat(award.date), + } + ) + # Sort all solves by date for team_id in solves_mapper: solves_mapper[team_id] = sorted(