Add caching to more API endpoints

This commit is contained in:
rubenwardy 2024-01-01 17:35:11 +00:00
parent 9e97a06f70
commit 376864db1b

@ -174,6 +174,7 @@ def resolve_package_deps(out, package, only_hard, depth=1):
@bp.route("/api/packages/<author>/<name>/dependencies/") @bp.route("/api/packages/<author>/<name>/dependencies/")
@is_package_page @is_package_page
@cors_allowed @cors_allowed
@cached(300)
def package_dependencies(package): def package_dependencies(package):
only_hard = request.args.get("only_hard") only_hard = request.args.get("only_hard")
@ -539,18 +540,21 @@ def package_scores():
@bp.route("/api/tags/") @bp.route("/api/tags/")
@cors_allowed @cors_allowed
@cached(60*60)
def tags(): def tags():
return jsonify([tag.as_dict() for tag in Tag.query.all() ]) return jsonify([tag.as_dict() for tag in Tag.query.all() ])
@bp.route("/api/content_warnings/") @bp.route("/api/content_warnings/")
@cors_allowed @cors_allowed
@cached(60*60)
def content_warnings(): def content_warnings():
return jsonify([warning.as_dict() for warning in ContentWarning.query.all() ]) return jsonify([warning.as_dict() for warning in ContentWarning.query.all() ])
@bp.route("/api/licenses/") @bp.route("/api/licenses/")
@cors_allowed @cors_allowed
@cached(60*60)
def licenses(): def licenses():
all_licenses = License.query.order_by(db.asc(License.name)).all() all_licenses = License.query.order_by(db.asc(License.name)).all()
return jsonify([{"name": license.name, "is_foss": license.is_foss} for license in all_licenses]) return jsonify([{"name": license.name, "is_foss": license.is_foss} for license in all_licenses])
@ -558,6 +562,7 @@ def licenses():
@bp.route("/api/homepage/") @bp.route("/api/homepage/")
@cors_allowed @cors_allowed
@cached(300)
def homepage(): def homepage():
query = Package.query.filter_by(state=PackageState.APPROVED) query = Package.query.filter_by(state=PackageState.APPROVED)
count = query.count() count = query.count()
@ -675,6 +680,7 @@ def user_view(username: str):
@bp.route("/api/users/<username>/stats/") @bp.route("/api/users/<username>/stats/")
@cors_allowed @cors_allowed
@cached(300)
def user_stats(username: str): def user_stats(username: str):
user = User.query.filter_by(username=username).first() user = User.query.filter_by(username=username).first()
if user is None: if user is None:
@ -687,6 +693,7 @@ def user_stats(username: str):
@bp.route("/api/cdb_schema/") @bp.route("/api/cdb_schema/")
@cors_allowed @cors_allowed
@cached(60*60)
def json_schema(): def json_schema():
tags = Tag.query.all() tags = Tag.query.all()
warnings = ContentWarning.query.all() warnings = ContentWarning.query.all()
@ -851,6 +858,8 @@ def collection_view(author, name):
@bp.route("/api/updates/") @bp.route("/api/updates/")
@cors_allowed
@cached(300)
def updates(): def updates():
protocol_version = get_int_or_abort(request.args.get("protocol_version")) protocol_version = get_int_or_abort(request.args.get("protocol_version"))
minetest_version = request.args.get("engine_version") minetest_version = request.args.get("engine_version")