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

Mongoid::Criteria objects are resolved in object filter #573

Open
william-stacken opened this issue Apr 25, 2024 · 1 comment
Open

Mongoid::Criteria objects are resolved in object filter #573

william-stacken opened this issue Apr 25, 2024 · 1 comment
Labels

Comments

@william-stacken
Copy link

william-stacken commented Apr 25, 2024

We are using an interactor that lists models. It accepts a Mongoid::Criteria as input and a filter that is used to limit the scope of the criteria further. Occasionally, this interactor would run very slowly, and we found that in the matches? method in object_filter.rb, the value is compared against nil. This means that if the value is a potentially expensive Mongoid::Criteria object, performance could be impacted as the criteria must be resolved to perform the comparison.

This may have already been considered, but would it be possible to use .nil? for comparision instead? This would leave the criteria unresolved.

@AaronLasseigne
Copy link
Owner

It's compared to nil because we support all Ruby objects including BasicObject. Unfortunately, BasicObject doesn't work with .nil?.

Having said that, people shouldn't really be throwing around BasicObject and it added complexity to the code that I'm not thrilled with. I'd consider removing that and using .nil?. It'll have to be in a major release though since it would technically be a breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants