Implement eager loading#393
Merged
dresende merged 1 commit intodresende:masterfrom Nov 27, 2013
Tape:eager-loading
Merged
Conversation
|
👍 good job :) |
|
Very nice, thanks mate! |
Collaborator
|
Really nice, passing tests and all. |
Owner
|
I like it :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
ImageandTagwith a relationshipImage.hasMany("tags", Tag). If I doImage.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 doImage.find(...).eager("tags").run(...). The returned result will be the same, but will be far more performant.