Learning hours roster aggregate is slow (161 ms, 74% of LearningHoursController#index)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 62/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Ambito
- database, performance
Direzione di ricerca
Start with app/models/learning_hour.rb and inspect the two roster aggregate methods, then review app/services/learning_hours_dashboard_rows_service.rb and the existing indexes before checking the query plan. The issue suggests a composite index, grouping change, or caching; preserve the casa_org_id scope and use the listed request and system specs to check behavior. Done means the aggregate is faster and cross organization scoping still works.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Problem
Scout APM, Slow Query Insights (7 days to 2026-11-15): the LearningHour roster aggregate behind LearningHoursController#index is 161 ms per query, 74% of that endpoint's response time. It is new this week.
Root cause
LearningHour.all_volunteers_learning_hours (admins) and supervisor_volunteers_learning_hours (supervisors) in app/models/learning_hour.rb join users, filter on users.casa_org_id and learning_hours.occurred_at, then GROUP BY users.display_name, users.id and SUM(...). learning_hours only has an index on user_id, so the occurred_at range filter scans every learning hour for the matching users. Cost grows with the number of entries ever logged.
The controller then does rows.to_a, searches and paginates in Ruby (app/controllers/learning_hours_controller.rb). That is fine at roster size, but the aggregate still runs in full on every page view, including every pagination click.
Suggested fix (pick one or combine)
- Run
EXPLAIN (ANALYZE, BUFFERS)on the query in a production console or a copy of the data and confirm a seq scan onlearning_hours. - Add a composite index
add_index :learning_hours, [:user_id, :occurred_at], algorithm: :concurrently(Strong Migrations requiresdisable_ddl_transaction!). Check the plan again afterwards. - Group by
users.idonly and selectMAX(users.display_name)(or useusers.idin the GROUP BY withusers.display_namefunctionally dependent, which Postgres allows whenidis the primary key). This avoids sorting and grouping on a text column. - Optional: cache the per-volunteer totals for the selected period for a few minutes (
Rails.cache.fetch, keyed by org, role and period), so pagination clicks do not re-run the aggregate. - Keep the cross-org check: the query must still be scoped to
casa_org_id. Runspec/requests/learning_hours_spec.rbandspec/system/learning_hours/.
Related: #6505 (ensure indexes present).
Difficulty: intermediate. Files: app/models/learning_hour.rb, app/services/learning_hours_dashboard_rows_service.rb, a new migration under db/migrate/.
- Lingua principale
- Ruby
- Stelle
- 384
- Fork
- 558
- Merge medio
- 1g 7h
- PR unite (30g)
- 63
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di rubyforgood/casa
-
⛓️ Security Difficulty: Easy Good First Issue Help Wanted ruby Type: Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
rubyforgood/casa#7404 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficulty: Easy Good First Issue Help Wanted ruby Type: Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
rubyforgood/casa#7402 ·
I maintainer di solito rispondono entro 1 giorno
-
Remove the bin/bundle binstub (Heroku warns it can break Bundler on deploy)Forse già presa @Akash-Dhanwate l’ha presa 8 giorni fa. Apertadependencies Difficulty: Easy Good First Issue
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 82/100
rubyforgood/casa#7325 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Reports page: move export-button disable/re-enable into a Stimulus controllerForse di nuovo libera @Akash-Dhanwate l’ha presa 9 giorni fa e non c’è nessuna pull request aperta. ApertaDifficulty: Easy Good First Issue Help Wanted javascript
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
rubyforgood/casa#7311 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
New case: use Stimulus for the "I don't know the court date yet" toggleForse di nuovo libera @Aryankn29 l’ha presa 9 giorni fa e non c’è nessuna pull request aperta. ApertaDifficulty: Easy Good First Issue Help Wanted javascript
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
rubyforgood/casa#7310 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di rubyforgood/casa
Issue simili
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
internetee/registry#2984 ·
I maintainer di solito rispondono entro 6 giorni
-
Redis Lua error `@user_script:52: ERR value is not an integer or out of range` when `window_size` is configuredForse già presa @mimosa l’ha presa oggi. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
riscv/riscv-unified-db#2829 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
docker-library/ruby#534 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100