Skip to content

perf(dashboard): project financial log summaries in PostgreSQL - #4481

Closed
TaprootFreak wants to merge 1 commit into
developfrom
agent/optimize-financial-dashboard-api
Closed

perf(dashboard): project financial log summaries in PostgreSQL#4481
TaprootFreak wants to merge 1 commit into
developfrom
agent/optimize-financial-dashboard-api

Conversation

@TaprootFreak

Copy link
Copy Markdown
Collaborator

Summary

Replace the stale SQL Server-oriented approach from #3725 with a PostgreSQL-native fix for GET /v1/dashboard/financial/log.

The endpoint currently loads complete FinancialDataLog.message snapshots for every minute in the requested range and parses them in Node, although the response only needs balance aggregates, one BTC price and balancesByFinancialType. For the default three-day view that means roughly 4,320 large JSON documents per request.

This PR adds a dashboard-specific PostgreSQL projection that returns only the fields required by the existing response contract. The API no longer transfers or parses the complete snapshot documents.

What changes

  • project the six dashboard values and grouped balances directly from message in PostgreSQL
  • keep the existing valid-row filters, chronological ordering and daily-sampling semantics
  • continue skipping malformed historical JSON rows, matching the previous endpoint behaviour
  • normalize raw PostgreSQL driver values before returning the unchanged DTO
  • route only the financial dashboard endpoint through the compact path; other financial-log consumers remain unchanged
  • rely on the composite financial-log index already merged in 7392bb63 - Index the financial-log query columns #4457; no additional migration, caching or silent downsampling

Why this scope

Grafana traces showed the database fetch/transfer of full log snapshots dominating the request. The approximately 2 MB response itself is not the main problem, and the only observed caller refreshes once per minute, so compression or a 30-second in-process cache would not address the root cause. Five-minute sampling would also change the dashboard data contract.

Verification

  • npm run type-check
  • npm run lint
  • npm run format:check
  • npm run build
  • targeted tests: 16 passed
  • full Jest suite: 5,967 passed, 165 skipped, 0 failed

Deployment check

After deploying to DEV, compare endpoint latency and response equality for the default three-day request before promoting.

@TaprootFreak
TaprootFreak force-pushed the agent/optimize-financial-dashboard-api branch from 7ec0667 to 3f2d583 Compare July 29, 2026 21:28
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