Learning hours roster aggregate is slow (161 ms, 74% of LearningHoursController#index)
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 62/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Domaine
- database, performance
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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/.
- Langage dominant
- Ruby
- Étoiles
- 384
- Forks
- 558
- Merge moyen
- 1 j 7 h
- PR mergées (30 j)
- 63
Préparer son environnement
Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.
- Fournit un Dockerfile ou un fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de rubyforgood/casa
-
⛓️ Security Difficulty: Easy Good First Issue Help Wanted ruby Type: Bug
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
rubyforgood/casa#7404 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulty: Easy Good First Issue Help Wanted ruby Type: Bug
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
rubyforgood/casa#7402 ·
Les mainteneurs répondent en général sous 1 jour
-
Remove the bin/bundle binstub (Heroku warns it can break Bundler on deploy)Peut-être pris @Akash-Dhanwate l’a pris il y a 8 jours. Ouvertedependencies Difficulty: Easy Good First Issue
Difficulté 1/5 Moins d'une heure Accessibilité débutants 82/100
rubyforgood/casa#7325 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Reports page: move export-button disable/re-enable into a Stimulus controllerPeut-être à nouveau libre @Akash-Dhanwate l’a pris il y a 9 jours, et aucune pull request n’est ouverte. OuverteDifficulty: Easy Good First Issue Help Wanted javascript
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
rubyforgood/casa#7311 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
New case: use Stimulus for the "I don't know the court date yet" togglePeut-être à nouveau libre @Aryankn29 l’a pris il y a 9 jours, et aucune pull request n’est ouverte. OuverteDifficulty: Easy Good First Issue Help Wanted javascript
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
rubyforgood/casa#7310 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de rubyforgood/casa
Issues similaires
-
enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 66/100
internetee/registry#2984 ·
Les mainteneurs répondent en général sous 6 jours
-
Redis Lua error `@user_script:52: ERR value is not an integer or out of range` when `window_size` is configuredPeut-être pris @mimosa l’a pris aujourd’hui. Ouvertebug
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 67/100
riscv/riscv-unified-db#2829 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
docker-library/ruby#534 ·
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100