Skip to content

CV2-6728: N+1 Query (DynamicAnnotation::Field)#2443

Merged
melsawy merged 1 commit into
developfrom
CV2-6728-n-1-query-dynamic-annotation-field
Jul 14, 2026
Merged

CV2-6728: N+1 Query (DynamicAnnotation::Field)#2443
melsawy merged 1 commit into
developfrom
CV2-6728-n-1-query-dynamic-annotation-field

Conversation

@melsawy

@melsawy melsawy commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Description

N+1 query occurs when run this GraphQL query

query { 
  # ID for verification_status Annotation
  node(id: "QW5ub3RhdGlvbi80NDE0OTYzNw==\n") { 
    ...F0 
  } 
}
fragment F0 on Annotation { 
  content
}

Calling to_json on the fields here triggers an N+1 query because each DynamicAnnotation::Field belongs to a field. During serialization, to_json performs a separate lookup for each associated FieldInstance. Using includes(:field_instance) eagerly loads the association, reducing the repeated queries to a single batched query.

References: CV2-6728

How to test?

Re-run unit tests

Checklist

  • I have performed a self-review of my code and ensured that it is safe and runnable, that code coverage has not decreased, and that there are no new Code Climate issues. I have also followed Meedan's internal coding guidelines.

@melsawy melsawy requested a review from caiosba July 14, 2026 09:22
@melsawy melsawy merged commit f77ca60 into develop Jul 14, 2026
12 of 13 checks passed
@melsawy melsawy deleted the CV2-6728-n-1-query-dynamic-annotation-field branch July 14, 2026 19:39
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.

2 participants