Skip to content

Optimize analytics overview queries#430

Merged
mrubens merged 2 commits into
developfrom
codex/optimize-analytics-queries
Jul 16, 2026
Merged

Optimize analytics overview queries#430
mrubens merged 2 commits into
developfrom
codex/optimize-analytics-queries

Conversation

@mrubens

@mrubens mrubens commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • replace separate chart and filter-option requests with one analytics overview request
  • extract only the fallback environment ID from task-run JSON instead of loading complete payloads for every usage event
  • resolve fallback environments only for referenced IDs
  • fetch PR attribution from deduplicated task IDs instead of rejoining all usage events
  • remove the superseded chart/filter hooks and add regression coverage

Why

The analytics page built the same row set independently for its chart and filter controls. Cost analytics also transferred complete task-run payloads and multiplied usage rows through its PR-attribution join. These patterns made request cost grow unnecessarily with inference-event volume.

Impact

Tasks and costs now load chart data and filter options from one consistent row snapshot. Cost analytics performs less database work and transfers substantially less JSON while preserving environment and pull-request attribution.

Validation

  • targeted database-backed cost analytics tests
  • analytics client behavior tests
  • @roomote/web TypeScript check
  • focused formatting and lint checks
  • pre-push oxlint, residual lint, fast type checks, and knip

@roomote-roomote

roomote-roomote Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

No code issues remain. See task

  • High apps/web/src/lib/server/analytics/cost-rows.ts:103-122 — Avoid an unbounded task-ID IN list for PR attribution. timePeriod: 'all' can return an arbitrary number of distinct tasks, and this query emits one bind per task; at 65,536 IDs the current driver fails with MAX_PARAMETERS_EXCEEDED (limit 65,534), so large installations lose cost analytics. Keep the deduplication in SQL/CTE form or chunk the lookup.

Reviewed b2386af

@mrubens
mrubens marked this pull request as ready for review July 16, 2026 16:53
@mrubens
mrubens merged commit 9b3812b into develop Jul 16, 2026
18 checks passed
@mrubens
mrubens deleted the codex/optimize-analytics-queries branch July 16, 2026 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant