Skip to content

fix(graphql): Resolve N+1 query for StudyLevel translations#507

Draft
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/graphql-studylevel-n1-query
Draft

fix(graphql): Resolve N+1 query for StudyLevel translations#507
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/graphql-studylevel-n1-query

Conversation

@sentry

@sentry sentry Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

This PR addresses an N+1 query issue identified in the GraphQL API when fetching StudyLevel objects and their associated translations.

Root Cause:
The StudyLevelNode.get_queryset method was not utilizing prefetch_related('translations'), leading to a separate database query for translations for each StudyLevel instance returned in the GraphQL response.

Changes Made:

  • Added prefetch_related('translations') to the StudyLevelNode.get_queryset method in occurrences/schema.py. This ensures that all related StudyLevelTranslation objects are fetched in a single, optimized query, significantly reducing the number of database calls.
  • Conducted a brief audit of other DjangoObjectType classes in occurrences/schema.py that use TranslatableModel to ensure similar N+1 patterns are not present for their translation fields. No other immediate issues were found in this scope.

Impact:
This change improves the performance of GraphQL queries involving StudyLevel translations by eliminating redundant database queries.

Fixes KULTUS-API-F

@sonarqubecloud

Copy link
Copy Markdown

@azure-pipelines

Copy link
Copy Markdown

KULTUS-API branch is deployed to platta: https://kultus-pr507.api.dev.hel.ninja 🚀🚀🚀

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.

0 participants