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

Avoid importing everything when given an empty relation #749

Merged
merged 3 commits into from
Feb 4, 2021

Conversation

dalthon
Copy link
Contributor

@dalthon dalthon commented Feb 4, 2021

Just a rebase of #698 with one more spec added to cover empty relations.

JF-Lalonde and others added 2 commits December 18, 2019 09:12
Users can currently call `import` and `import!` directly on an index. If
these methods are called without arguments, the index imports all data
matching the type definition.
If these methods are called with an argument, ex.
`UsersIndex.import(User.where('rating > 100'))`, only the given scope or
array will be imported into the index.
If these methods are called with an argument, but that argument is empty
(for example `User.where('rating > 100')` returns an empty relation),
the methods were behaving as if they had no args (importing all the data
for an index).
This is undesired behavior, as the expectation should be for an import
with an argument that is empty to import nothing.
The changes proposed here mirror the changes created in this
[commit](2eeff14), so that the behavior of doing `UsersIndex.import([])` is the same as doing `UsersIndex::User.import([])`.
Copy link
Contributor

@rabotyaga rabotyaga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a CHANGELOG entry

@dalthon dalthon force-pushed the empty-relation-import branch 3 times, most recently from c8a4b46 to e1bb4a2 Compare February 4, 2021 12:28
@dalthon dalthon merged commit 3f6eb82 into master Feb 4, 2021
@rabotyaga rabotyaga deleted the empty-relation-import branch February 4, 2021 12:40
cyucelen pushed a commit to cyucelen/chewy that referenced this pull request Jan 28, 2023
* Avoid importing everything when given an empty relation
* Add spec to cover empty relations

Co-authored-by: JF Lalonde <lalondej88@gmail.com>
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.

3 participants