Cache challenge data for faster loading of /api/v1/challenges (#2232)

* Improve response time of `/api/v1/challenges` and `/api/v1/challenges/[challenge_id]/solves`
* Rewrite and remove _build_solves_query to make it cacheable
* Closes #2209
This commit is contained in:
Kevin Chung
2022-12-05 00:10:30 -05:00
committed by GitHub
parent 800fb8260a
commit d89ac579f2
12 changed files with 356 additions and 132 deletions

View File

@@ -15,7 +15,7 @@ from sqlalchemy_utils import drop_database
from werkzeug.datastructures import Headers
from CTFd import create_app
from CTFd.cache import cache, clear_standings
from CTFd.cache import cache, clear_challenges, clear_standings
from CTFd.config import TestingConfig
from CTFd.models import (
Awards,
@@ -336,6 +336,7 @@ def gen_challenge(
)
db.session.add(chal)
db.session.commit()
clear_challenges()
return chal
@@ -455,6 +456,7 @@ def gen_solve(
db.session.add(solve)
db.session.commit()
clear_standings()
clear_challenges()
return solve