Skip to content

Best way to do finds with many includes? #4125

Closed

Description

@ryanpon

I commonly need to do queries that use many includes, for example:

User.find({
  where: ...,
  include: [Pet, Car, FavoriteMovie, KitchenSink]
});

This becomes expensive quickly since the data set returned is a function of num(Pet) * num(Car) * num(FavoriteMovie) * num(KitchenSink). Other than explicitly doing separate queries by either call find multiple times or doing a lazy load with get<associationName>, is there a good way to mitigate this issue?

I have a fix for this locally that automatically splits find calls into multiple queries when there is more than one include and transparently merges the result back together. What do you think about this approach?

Activity

  1. mickhansen commented on Jul 16, 2015

    @mickhansen
    Contributor

    include.seperate which would offer you the oppurtunity to split an include into a seperate call to avoid the costly deduplication logic is on the roadmap: #2869

    I hope to start on it soon.

  2. added
    type: feature
    type: refactor
    on Jul 16, 2015
  3. mickhansen commented on Jul 23, 2015

    @mickhansen
    Contributor

    Working on support for hasMany here: #4177

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

    type: featuretype: refactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions