Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement eager loading #393

Merged
merged 1 commit into from
Nov 27, 2013
Merged

Implement eager loading #393

merged 1 commit into from
Nov 27, 2013

Conversation

Tape
Copy link
Contributor

@Tape Tape commented Nov 20, 2013

Description

Here's a simple implementation of eager loading (NOTE: I am not familiar with MongoDB so this will need to be added or refactored in a way that Mongo can handle it, I left relevant TODO comments on what to remove). Autofetch on large queries can be quite detrimental and this should help remedy the problem. This should also resolve #389, however bulk updates should be added.

How it works

Assume I have a database table with the models Image and Tag with a relationship Image.hasMany("tags", Tag). If I do Image.find(...).run(...) currently it will do n+1 queries (query for images, n queries for tags). The implementation I have provided will only perform two queries to fetch the data. In order to use it, autofetch can be left off and do Image.find(...).eager("tags").run(...). The returned result will be the same, but will be far more performant.

@vendethiel
Copy link

👍 good job :)

@HMCardcash
Copy link

Very nice, thanks mate!

@dxg
Copy link
Collaborator

dxg commented Nov 25, 2013

Really nice, passing tests and all.
I'd like to merge this, but want some input from @dresende given it's significant new functionality..

@dresende
Copy link
Owner

I like it :)

dresende added a commit that referenced this pull request Nov 27, 2013
@dresende dresende merged commit d393b98 into dresende:master Nov 27, 2013
@Tape Tape deleted the eager-loading branch November 27, 2013 16:19
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.

(Question) Including specific associations and one more
5 participants