Cache scoreboard page (#1025)

* Cache the `/scoreboard` page to avoid having to rebuild the response so often
* Update `tests.api.v1.test_scoreboard:test_scoreboard_is_cached` to also test if `/scoreboard` is cached
selenium-screenshot-testing
Kevin Chung 2019-06-16 13:29:50 -04:00 committed by GitHub
parent e627391b12
commit b5632f9289
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 0 deletions

View File

@ -33,6 +33,7 @@ def clear_standings():
cache.delete_memoized(get_standings)
cache.delete_memoized(get_team_standings)
cache.delete_memoized(get_user_standings)
cache.delete(make_cache_key(path="scoreboard.listing"))
cache.delete(make_cache_key(path=api.name + "." + ScoreboardList.endpoint))
cache.delete(make_cache_key(path=api.name + "." + ScoreboardDetail.endpoint))
cache.delete_memoized(ScoreboardList.get)

View File

@ -1,5 +1,6 @@
from flask import render_template, Blueprint
from CTFd.cache import cache, make_cache_key
from CTFd.utils import config
from CTFd.utils.decorators.visibility import check_score_visibility
@ -10,6 +11,7 @@ scoreboard = Blueprint("scoreboard", __name__)
@scoreboard.route("/scoreboard")
@check_score_visibility
@cache.cached(timeout=60, key_prefix=make_cache_key)
def listing():
standings = get_standings()
return render_template(

View File

@ -39,8 +39,14 @@ def test_scoreboard_is_cached():
client.get("/api/v1/scoreboard/top/10")
assert app.cache.get("view/api.scoreboard_scoreboard_detail")
# Check scoreboard page
assert app.cache.get('view/scoreboard.listing') is None
client.get("/scoreboard")
assert app.cache.get('view/scoreboard.listing')
# Empty standings and check that the cached data is gone
clear_standings()
assert app.cache.get("view/api.scoreboard_scoreboard_list") is None
assert app.cache.get("view/api.scoreboard_scoreboard_detail") is None
assert app.cache.get('view/scoreboard.listing') is None
destroy_ctfd(app)