Performance on selecting all columns instead of specified attributes
kevintraver opened this issue · 0 comments
kevintraver commented
Is there a reason the _model_class
queries all columns?
jsonapi-resources/lib/jsonapi/active_relation_resource.rb
Lines 286 to 288 in bf4b4cd
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.