You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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
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.This should also take into account sparse fieldsets parameters, which would further limit which columns are selected.
The text was updated successfully, but these errors were encountered: