Skip to content

Fix N+1 queries in equipment views, add DRF pagination#32

Merged
joefarrelly merged 1 commit into
devfrom
fix/n-plus-one-queries
Jun 18, 2026
Merged

Fix N+1 queries in equipment views, add DRF pagination#32
joefarrelly merged 1 commit into
devfrom
fix/n-plus-one-queries

Conversation

@joefarrelly

Copy link
Copy Markdown
Owner

Summary

  • _list_all: materialise DataEquipmentVariant into a dict before the loop — was calling variants.filter().first() per slot per alt (N queries per alt × 18 slots)
  • _list_single: batch-fetch DataEquipment and DataEquipmentVariant in two queries upfront — was hitting the DB twice per slot (36 queries per request for 18 slots)
  • Add REST_FRAMEWORK pagination config (PageNumberPagination, PAGE_SIZE=100) for the raw ModelViewSet data endpoints; custom list() overrides in profile views are unaffected

_list_all: materialise DataEquipmentVariant into a dict before the
loop — was calling variants.filter().first() per slot per alt.

_list_single: batch-fetch DataEquipment and DataEquipmentVariant in
two queries before the loop — was hitting the DB twice per slot
(36 queries per request for 18 slots).

Add REST_FRAMEWORK pagination (PageNumberPagination, page_size=100)
to settings for the raw ModelViewSet data endpoints.
@joefarrelly joefarrelly merged commit 193c122 into dev Jun 18, 2026
2 checks passed
@joefarrelly joefarrelly deleted the fix/n-plus-one-queries branch June 18, 2026 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant