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

Postgres query service should use find_each in #find_all and #find_all_of_model for efficiency #924

Closed
dchandekstark opened this issue Mar 17, 2023 · 1 comment · Fixed by #925

Comments

@dchandekstark
Copy link
Member

https://api.rubyonrails.org/classes/ActiveRecord/Batches.html#method-i-find_each

For example, current code using .all:

    def find_all
      orm_class.all.lazy.map do |orm_object|
        resource_factory.to_resource(object: orm_object)
      end
    end

Could be updated to

    def find_all
      orm_class.find_each.lazy.map do |orm_object|
        resource_factory.to_resource(object: orm_object)
      end
    end

#find_all_of_model has a where clause, but it could still benefit from find_each since that can be a large query.

@tpendragon
Copy link
Collaborator

Yeah that sounds great! We do something similar in the sequel plugin.

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 a pull request may close this issue.

2 participants