Skip to content

Commit

Permalink
fix(api): optimize json-cid view queries
Browse files Browse the repository at this point in the history
Use select_related to reduce queries on json_cid_export view
  • Loading branch information
dchiller committed Oct 8, 2024
1 parent cc14cf5 commit 7a3eeea
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion django/cantusdb_project/main_app/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,13 @@ def json_cid_export(request, cantus_id: str) -> JsonResponse:
"""

# the API in OldCantus appears to only return chants, and no sequences.
chants = Chant.objects.filter(cantus_id=cantus_id).filter(source__published=True)
chants = (
Chant.objects.select_related(
"source", "source__holding_institution", "feast", "genre", "service"
)
.filter(cantus_id=cantus_id)
.filter(source__published=True)
)
chant_dicts = [{"chant": build_json_cid_dictionary(c, request)} for c in chants]
response = {"chants": chant_dicts}
return JsonResponse(response)
Expand Down

0 comments on commit 7a3eeea

Please sign in to comment.