Speed improvements (#2084)

* Improve speed of `/api/v1/teams/me/fails`
* Improve speed of `/api/v1/teams/[team_id]/fails`
* Improve speed of `/api/v1/users/me/fails`
* Improve speed of `/api/v1/users/[user_id]/fails`
This commit is contained in:
Kevin Chung
2022-04-08 21:21:42 -04:00
committed by GitHub
parent 281ae12a7c
commit c95591aa16
2 changed files with 36 additions and 22 deletions

View File

@@ -512,17 +512,20 @@ class TeamPrivateFails(Resource):
view = "admin" if is_admin() else "user"
schema = SubmissionSchema(view=view, many=True)
response = schema.dump(fails)
if response.errors:
return {"success": False, "errors": response.errors}, 400
# We want to return the count purely for stats & graphs
# but this data isn't really needed by the end user.
# Only actually show fail data for admins.
if is_admin():
schema = SubmissionSchema(view=view, many=True)
response = schema.dump(fails)
if response.errors:
return {"success": False, "errors": response.errors}, 400
data = response.data
else:
data = []
count = len(response.data)
count = len(fails)
return {"success": True, "data": data, "meta": {"count": count}}
@@ -581,17 +584,20 @@ class TeamPublicFails(Resource):
view = "admin" if is_admin() else "user"
schema = SubmissionSchema(view=view, many=True)
response = schema.dump(fails)
if response.errors:
return {"success": False, "errors": response.errors}, 400
# We want to return the count purely for stats & graphs
# but this data isn't really needed by the end user.
# Only actually show fail data for admins.
if is_admin():
schema = SubmissionSchema(view=view, many=True)
response = schema.dump(fails)
if response.errors:
return {"success": False, "errors": response.errors}, 400
data = response.data
else:
data = []
count = len(response.data)
count = len(fails)
return {"success": True, "data": data, "meta": {"count": count}}

View File

@@ -351,16 +351,20 @@ class UserPrivateFails(Resource):
fails = user.get_fails(admin=True)
view = "user" if not is_admin() else "admin"
response = SubmissionSchema(view=view, many=True).dump(fails)
if response.errors:
return {"success": False, "errors": response.errors}, 400
# We want to return the count purely for stats & graphs
# but this data isn't really needed by the end user.
# Only actually show fail data for admins.
if is_admin():
response = SubmissionSchema(view=view, many=True).dump(fails)
if response.errors:
return {"success": False, "errors": response.errors}, 400
data = response.data
else:
data = []
count = len(response.data)
count = len(fails)
return {"success": True, "data": data, "meta": {"count": count}}
@@ -418,16 +422,20 @@ class UserPublicFails(Resource):
fails = user.get_fails(admin=is_admin())
view = "user" if not is_admin() else "admin"
response = SubmissionSchema(view=view, many=True).dump(fails)
if response.errors:
return {"success": False, "errors": response.errors}, 400
# We want to return the count purely for stats & graphs
# but this data isn't really needed by the end user.
# Only actually show fail data for admins.
if is_admin():
response = SubmissionSchema(view=view, many=True).dump(fails)
if response.errors:
return {"success": False, "errors": response.errors}, 400
data = response.data
else:
data = []
count = len(response.data)
count = len(fails)
return {"success": True, "data": data, "meta": {"count": count}}