Learning hours roster aggregate is slow (161 ms, 74% of LearningHoursController#index)
Maintainer antworten meist innerhalb von 1 Tag
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 62/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Aktiv
- Bereich
- database, performance
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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/.
- Vorherrschende Sprache
- Ruby
- Sterne
- 384
- Forks
- 558
- Ø Merge
- 1 T. 7 Std.
- Gemergte PRs (30 T.)
- 63
Entwicklungsumgebung
Startet den Dev-Container des Projekts im Browser, mit Ihrem eigenen GitHub-Konto.
- Enthält ein Dockerfile oder eine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus rubyforgood/casa
-
⛓️ Security Difficulty: Easy Good First Issue Help Wanted ruby Type: Bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
rubyforgood/casa#7404 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Difficulty: Easy Good First Issue Help Wanted ruby Type: Bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
rubyforgood/casa#7402 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Remove the bin/bundle binstub (Heroku warns it can break Bundler on deploy)Evtl. vergeben @Akash-Dhanwate hat das vor 8 Tagen übernommen. Offendependencies Difficulty: Easy Good First Issue
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 82/100
rubyforgood/casa#7325 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Reports page: move export-button disable/re-enable into a Stimulus controllerEvtl. wieder frei @Akash-Dhanwate hat das vor 9 Tagen übernommen, und es ist kein Pull Request offen. OffenDifficulty: Easy Good First Issue Help Wanted javascript
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
rubyforgood/casa#7311 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
New case: use Stimulus for the "I don't know the court date yet" toggleEvtl. wieder frei @Aryankn29 hat das vor 9 Tagen übernommen, und es ist kein Pull Request offen. OffenDifficulty: Easy Good First Issue Help Wanted javascript
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
rubyforgood/casa#7310 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in rubyforgood/casa
Ähnliche Issues
-
enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
internetee/registry#2984 ·
Maintainer antworten meist innerhalb von 6 Tagen
-
Redis Lua error `@user_script:52: ERR value is not an integer or out of range` when `window_size` is configuredEvtl. vergeben @mimosa hat das heute übernommen. Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 67/100
riscv/riscv-unified-db#2829 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
docker-library/ruby#534 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100