Paradaux
IssuesPAR-129Done
0

Fix slow SSR queries on /me and /transactions (pool exhaustion)

Faro web-vitals (Loki, 7d) show /me TTFB p90 ≈ 47s, p99 pinned at the 50s timeout. Root causes:

A. /me (lib/sql/me.ts)getPlayerCounterparties self-joins ledger_postings with no time window and resolves the player's account set via repeated IN (SELECT … UNION …) subqueries; getPlayerTrajectory/countPlayerTransactions repeat the same UNION-subquery pattern. Fix: resolve account-id list once in the page (from findAccountsForPlayer), pass an explicit account_id IN (…), and add the 90-day window to counterparties.

B. /transactions (lib/sql/ledger.ts)listTransactions joins all ledger_postings + GROUP BY to compute posting_count before ORDER BY settlement_time LIMIT 50 → O(whole ledger) per load. Fix: order+limit ledger_txns first (idx_ledger_settle_time), compute posting_count via correlated subquery for the 50 rows; drop the firm_players join in countTransactions when q is null.

C. Pool/guardrail (lib/db.ts)connectionLimit 10 → a 47s query starves the pool and stalls the whole site. Bump default pool to 100 and add SET SESSION max_execution_time on new connections as a runaway-query backstop.

V9 read-path indexes confirmed applied in prod.

Comments

No comments yet.

Activity

  • ParadauxIO linked a commit — Commit 76d044c — Perceived-latency pass: loading skeletons, nav prefetch, lean auth path, /chestshop cache (PAR-133)Jun 7, 2026, 7:41 PM
  • ParadauxIO linked a pull request — PR #10 merged — Release economy-explorer → main (perceived-latency pass, PAR-133)Jun 7, 2026, 7:41 PM
  • ParadauxIO linked a pull request — PR #10 open — Release economy-explorer → main (perceived-latency pass, PAR-133)Jun 7, 2026, 7:40 PM
  • ParadauxIO linked a pull request — PR #9 open — Release economy-explorer → main (perf fixes + 1.1.0 RBAC/RUM)Jun 7, 2026, 7:36 PM
  • ParadauxIO linked a commit — Commit 76d044c — Perceived-latency pass: loading skeletons, nav prefetch, lean auth path, /chestshop cache (PAR-133)Jun 7, 2026, 7:35 PM
  • ParadauxIO linked a commit — Commit cc7bd3a — Use MariaDB max_statement_time for the query backstop (PAR-129)Jun 7, 2026, 7:14 PM
  • ParadauxIO linked a commit — Commit 7ccc3c7 — Cache /market aggregates; drop needless countAccounts join (PAR-130)Jun 7, 2026, 7:14 PM
  • ParadauxIO linked a commit — Commit 42d2c9b — Fix slow /me and /transactions SSR queries (PAR-129)Jun 7, 2026, 7:14 PM
  • ParadauxIO changed status to Status → DoneJun 7, 2026, 7:14 PM
  • ParadauxIO linked a pull request — PR #9 merged — Release economy-explorer → main (perf fixes + 1.1.0 RBAC/RUM)Jun 7, 2026, 7:14 PM
  • ParadauxIO linked a pull request — PR #9 open — Release economy-explorer → main (perf fixes + 1.1.0 RBAC/RUM)Jun 7, 2026, 7:10 PM
  • ParadauxIO linked a commit — Commit cc7bd3a — Use MariaDB max_statement_time for the query backstop (PAR-129)Jun 7, 2026, 7:10 PM
  • ParadauxIO linked a pull request — PR #9 open — Release economy-explorer → main (perf fixes + 1.1.0 RBAC/RUM)Jun 7, 2026, 7:06 PM
  • ParadauxIO linked a commit — Commit 7ccc3c7 — Cache /market aggregates; drop needless countAccounts join (PAR-130)Jun 7, 2026, 7:05 PM
  • ParadauxIO linked a commit — Commit 42d2c9b — Fix slow /me and /transactions SSR queries (PAR-129)Jun 7, 2026, 7:05 PM
  • tesks changed status to Status → Pending ReleaseJun 7, 2026, 6:50 PM
  • tesks created the issueJun 7, 2026, 6:46 PM