JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

Performance on selecting all columns instead of specified attributes

オープン
#1,389 コメント 0 件 リアクション 2 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Ruby
スター
2.3k
フォーク
546
PR マージ指標
30日以内にマージされた PR はありません

説明

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.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

lib/jsonapi/active_relation_resource.rb のリンクされた _model_class クエリから始め、Resource の属性と sparse fieldsets がどのように表現されているかを追跡します。これらのクエリが resource とリクエストされた fieldset に必要なフィールドだけを選択し、既存の records の動作を維持しながら、関連するクエリパスを網羅できた時点で作業は完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
rails, ruby
領域
backend-api-design, databases, performance
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。