Speed up signed-in dashboard with rollup-backed today and goals data#1169
Speed up signed-in dashboard with rollup-backed today and goals data#1169skyfallwastaken wants to merge 6 commits intomainfrom
Conversation
Greptile SummaryThis PR introduces rollup-backed today stats (new Confidence Score: 5/5Safe to merge — all three previous P0/P1 findings are resolved, and no new blocking issues were found. The stale rollup guard, language count inflation fix (simple GROUP BY COUNT), and No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Browser
participant Controller as StaticPagesController
participant DD as DashboardData concern
participant Cache as Rails.cache
participant Rollup as DashboardRollup (DB)
participant DRRS as DashboardRollupRefreshService
participant PGPS as ProgrammingGoalsProgressService
Browser->>Controller: GET / (signed in)
Controller->>DD: dashboard_stats_payload (deferred)
Note over DD: today_stats_data
DD->>Cache: fetch("user/:id/today_stats/:tz/:date", 1.min)
alt Cache hit
Cache-->>DD: cached today stats
else Cache miss
DD->>Rollup: dashboard_rollup_grouped_rows
alt Context matches (tz + date)
Rollup-->>DD: today context/total/language/editor rows
DD->>DD: build_today_stats_from_rollup_data
else Context stale or missing
DD->>DRRS: today_rollup_data_for(user)
DRRS->>Rollup: heartbeats.today (queries)
DRRS-->>DD: today_data hash
DD->>DRRS: upsert_today_rollup! (advisory lock)
DRRS->>Rollup: DELETE today dims + INSERT new rows
DD->>DD: clear rollup rows memo
DD->>DD: build_today_stats_from_rollup_data
end
DD->>Cache: store result
end
Note over DD: programming_goals_progress_data
DD->>Rollup: dashboard_rollup_rows (re-fetch if memo cleared)
DD->>PGPS: new(user, goals, rollup_rows)
loop each goal
alt Has GOALS_PERIOD_TOTAL rows AND not AND-type goal
PGPS->>PGPS: tracked_seconds_from_rollup
else Missing goals dims OR project+language AND goal
PGPS->>Rollup: heartbeats.where(time: period) (fallback)
end
end
PGPS-->>DD: goals progress array
DD-->>Controller: dashboard_stats_payload
Controller-->>Browser: Inertia props
Reviews (2): Last reviewed commit: "Use bigint-safe advisory lock key for to..." | Re-trigger Greptile |
There was a problem hiding this comment.
Pull request overview
This PR aims to speed up the signed-in dashboard by serving “today stats”, activity graph daily durations, and (some) programming goals progress from DashboardRollup rows instead of running per-request heartbeat queries.
Changes:
- Extend
DashboardRollupRefreshServiceto persist rollups for daily durations, today-context/today-stats, and goals-period aggregates. - Update dashboard controllers/concerns to read today stats + activity graph data from rollups (with cache + staleness handling) and to pass rollup rows into goals progress calculation.
- Add/extend tests covering rollup generation, rollup-backed goals progress behavior, today-context staleness refresh, and timezone-change cache invalidation + rollup refresh scheduling.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
app/services/dashboard_rollup_refresh_service.rb |
Generates new rollup dimensions for daily durations, today stats, and goal-period aggregates; adds targeted today upsert. |
app/controllers/concerns/dashboard_data.rb |
Uses rollup-backed daily durations and today stats with cache/staleness logic; centralizes rollup row memoization. |
app/controllers/static_pages_controller.rb |
Switches goals progress payload to use ProgrammingGoalsProgressService with rollup rows (removes prior cache wrapper). |
app/services/programming_goals_progress_service.rb |
Adds optional rollup-backed tracked-seconds computation for unfiltered / project-only / language-only goals. |
app/models/dashboard_rollup.rb |
Adds new allowed dimension names for the new rollup records. |
app/models/user.rb |
Adjusts timezone-change handling to clear timezone-specific cache keys and schedule immediate rollup refresh. |
test/services/dashboard_rollup_refresh_service_test.rb |
Adds assertions for new rollup dimensions/records (daily durations, today stats, goals totals). |
test/services/programming_goals_progress_service_test.rb |
Adds coverage for rollup-backed goals progress and query fallback for combined filters. |
test/controllers/concerns/dashboard_data_test.rb |
Verifies today stats refreshes rollup-backed data when rollup context is stale. |
test/models/user_test.rb |
Verifies timezone change clears related caches and enqueues immediate rollup refresh. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot @greptileai Can I get a review? |
Reviewed. The fallback-goals assertion issue was addressed in |
|
@greptileai can I have review ty |
| DashboardRollup.transaction do | ||
| lock_key = today_rollup_lock_key(user.id) | ||
| DashboardRollup.connection.execute( | ||
| "SELECT pg_advisory_xact_lock(#{lock_key})" |
No description provided.