Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Performance on selecting all columns instead of specified attributes

Open
#1,389 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
38/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Stale
Tech stack
rails, ruby

Research direction

Start in lib/jsonapi/active_relation_resource.rb at the linked _model_class query and trace how Resource attributes and sparse fieldsets are represented. The work is done when those queries select only the fields needed by the resource and request fieldset, while preserving the existing records behavior and covering the relevant query paths.

Written by the indexing model from the issue text.

Description

Is there a reason the _model_class queries all columns?

https://github.com/cerebris/jsonapi-resources/blob/bf4b4cd7d79da453372880068e167066f0d05f47/lib/jsonapi/active_relation_resource.rb#L286-L288

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.

Dominant language
Ruby
Stars
2.3k
Forks
546
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from JSONAPI-Resources/jsonapi-resources

All issues in JSONAPI-Resources/jsonapi-resources

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.