Skip to content

CV2-6731: N+1 Query (get_fields)#2444

Merged
melsawy merged 1 commit into
developfrom
CV2-6731-n-1-query-get-fields
Jul 15, 2026
Merged

CV2-6731: N+1 Query (get_fields)#2444
melsawy merged 1 commit into
developfrom
CV2-6731-n-1-query-get-fields

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 fields triggers an N+1 query because each DynamicAnnotation::Field belongs to Annotation. During serialization, to_json performs a separate lookup for each associated Annotations. Using includes(:field_instance, :annotation) eagerly loads the association, reducing the repeated queries to a single batched query.

References: CV2-6731

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 20:07
@melsawy
melsawy merged commit 8d77428 into develop Jul 15, 2026
12 of 13 checks passed
@melsawy
melsawy deleted the CV2-6731-n-1-query-get-fields branch July 15, 2026 01:28
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