Skip to content

[Bug] Sideload Allowlist causes n+1 queries #487

@Reizar

Description

@Reizar

Hi,

We've been getting hit hard with n+1 queries in our codebase and its been causing quite a few issues. We do a lot of nested includes in our models but I thought Graphiti was supposed to handle loading them without n+1 queries.

I set up a new codebase and mirrored some of our models/associations to see if I could work out what the cause of the issue is. And I've found that when the sideload_allowlist is used, the n+1 queries happen. When I remove it, eager loading is used correctly.

Please see this codebase: https://github.com/Reizar/graphiti-nplus1-example for a reproduction of the issue.

Steps to reproduce:

  1. Clone codebase linked above.
  2. Run rails db:migrate
  3. Run rails db:seed
  4. Run rails server -p 5000
  5. Visit: http://127.0.0.1:5000/api/v1/inspections?include=tenancy.tenancy_memberships.user,tenancy.property&page[number]=1&page[size]=100

You should see the rails console filled with tonnes of DB queries.

Then:

  1. Open up app/controllers/inspections_controller.rb
  2. Comment out the self.sideload_allowlist = code
  3. Visit the url above again
  4. The queries should be reduced down to just the number of associations.

Feels like this is probably a bug, but it could also be an issue on our side of how we're using the sideload allowlist. Happy to hear any thoughts or provide additional information.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions