VolunteersController#index: one big datatable query is 105 ms (37% of response time)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 38/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 領域
- backend, databases, performance
調査の方向性
Start with app/datatables/volunteer_datatable.rb and trace raw_records, index_count, and the default display_name sort; use the default request's EXPLAIN (ANALYZE, BUFFERS) plan to identify the expensive node. Keep the organization policy scope, then run spec/system/volunteers/ and spec/datatables/volunteer_datatable_spec.rb; done means the query work is reduced without breaking the scoped results or filters.
索引モデルが issue の本文から書いたものです。
説明
Problem
Scout APM, Slow Query Insights (7 days to 2026-11-15): the Volunteer query behind VolunteersController#index is 105 ms per query and 37% of the endpoint's response time. First seen about 3 months ago.
#7279 (closed) fixed the page loading every case contact in the org. This is the next cost: the one big query that is left.
Root cause
VolunteerDatatable#raw_records (app/datatables/volunteer_datatable.rb) builds one SELECT with several LEFT JOINed subqueries (transition-aged-youth cases, most recent attempt using a window function over case_contacts, contacts in the past days, hours in the past 30 days), then filters, orders on a computed alias and applies OFFSET/LIMIT. Postgres has to compute every subquery for every volunteer in the org before it can sort and cut a page of 25. index_count then runs a second COUNT(DISTINCT users.id) over the same joins.
Suggested fix (pick one or combine)
- Run
EXPLAIN (ANALYZE, BUFFERS)for the default request (active, sorted bydisplay_name) and find the slowest node. Paste the plan in a comment. - Make
index_countcheaper: the count does not need themost_recent_attemptsor hours subqueries unless a filter uses them. Build the count frombase_relationplus only the joins the active filters need. - For the default sort (
display_name), page first (25 ids with LIMIT) and then compute the subquery columns only for those 25 volunteers, asdataalready does for the DataTables JSON path (active_case_counts_forand friends). - Check the indexes behind the subqueries:
case_contacts (creator_id, occurred_at)andcase_assignments (volunteer_id, active). Add them concurrently if missing (see #6505). - Keep the org scope: the data must still come from
policy_scope(current_organization.volunteers). Runspec/system/volunteers/andspec/datatables/volunteer_datatable_spec.rb.
Difficulty: intermediate to advanced (SQL). Files: app/datatables/volunteer_datatable.rb, app/controllers/volunteers_controller.rb.
- 主要言語
- Ruby
- スター
- 384
- フォーク
- 558
- 平均マージ
- 1日 7時間
- マージ済み PR(30日)
- 63
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
rubyforgood/casa のほかの issue
-
⛓️ Security Difficulty: Easy Good First Issue Help Wanted ruby Type: Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
rubyforgood/casa#7404 ·
メンテナーはふだん 1 日以内に返信
-
Difficulty: Easy Good First Issue Help Wanted ruby Type: Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
rubyforgood/casa#7402 ·
メンテナーはふだん 1 日以内に返信
-
Remove the bin/bundle binstub (Heroku warns it can break Bundler on deploy)対応中かも @Akash-Dhanwate が 8 日前に担当しました。 オープンdependencies Difficulty: Easy Good First Issue
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
rubyforgood/casa#7325 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
Reports page: move export-button disable/re-enable into a Stimulus controller再び着手できるかも @Akash-Dhanwate が 9 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンDifficulty: Easy Good First Issue Help Wanted javascript
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
rubyforgood/casa#7311 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
New case: use Stimulus for the "I don't know the court date yet" toggle再び着手できるかも @Aryankn29 が 9 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンDifficulty: Easy Good First Issue Help Wanted javascript
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
rubyforgood/casa#7310 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
rubyforgood/casa の issue をすべて見る
似ている issue
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
internetee/registry#2984 ·
メンテナーはふだん 6 日以内に返信
-
Redis Lua error `@user_script:52: ERR value is not an integer or out of range` when `window_size` is configured対応中かも @mimosa が今日担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
riscv/riscv-unified-db#2829 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
docker-library/ruby#534 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100