Skip to content

Performance on selecting all columns instead of specified attributes #1389

Open
@kevintraver

Description

@kevintraver

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions