Skip to content

Fix N+1 Query Issue in Owners-Pets Retrieval-created-by-agentic #434

Description

@asafchen-dig

There is an N+1 query performance issue in the /owners endpoint where the application makes one query to fetch owners followed by N separate queries to fetch each owner's pets.

Root Cause:

  • EAGER fetching of pets collection in Owner entity
  • Missing fetch join optimization in repository queries
  • No batch fetching configuration

Solution:

  1. Changed fetch type to LAZY to prevent unnecessary loading
  2. Added @EntityGraph for optimized loading when needed
  3. Implemented @batchsize for efficient batch fetching

A pull request has been created with these changes: #433

This issue is being tracked as part of incident #6b373e96-616c-11f0-a2c1-c67c199f5e31

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions