cerebris/jsonapi-resources

Performance on selecting all columns instead of specified attributes

kevintraver opened this issue · 0 comments

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.