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

Performance on selecting all columns instead of specified attributes #1389

Open
kevintraver opened this issue May 24, 2022 · 0 comments
Open

Comments

@kevintraver
Copy link
Contributor

Is there a reason the _model_class queries all columns?

def records_base(_options = {})
_model_class.all
end

This is a huge performance impact on models with many columns that may not ever be used by the resource.

It seems for performance reasons it makes sense to only select the attributes defined in the JSONAPI::Resource class.

A workaround for now is to override each resource using .select to retrieve only the fields that are specifically defined.

attributes :name, :address

def self.records(_options = {})
  super.select(self.fields)
end

This should also take into account sparse fieldsets parameters, which would further limit which columns are selected.

@kevintraver kevintraver changed the title Performance on selecting all columns instead of specified atttributes Performance on selecting all columns instead of specified attributes May 24, 2022
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

No branches or pull requests

1 participant