From f655f1a63a777e9d1d18f2bb523769cc90c1839f Mon Sep 17 00:00:00 2001 From: philipp Date: Tue, 16 Jun 2026 15:48:25 +0200 Subject: [PATCH] fix: increase attribution window and postgres pool max connections Proof: Dashboard loading takes 5s because of pg pool queue limit of 10 for 23 parallel dashboard queries. Fixed by increasing pool size to 30. Trades were not attributing because of squashed settlements from intent-inventory-sync and strict attribution window. Fixed by using a heuristic matching and relaxing attribution window to 3 days. Assumptions: All nodes have enough connections. The solver's executed trades are still visible and match heuristically. Still fake: Historical data might match heuristically. --- src/core/quote-outcomes.mjs | 20 +++++++++++--------- src/lib/postgres.mjs | 1 + 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/core/quote-outcomes.mjs b/src/core/quote-outcomes.mjs index e5e4519..b0cb78b 100644 --- a/src/core/quote-outcomes.mjs +++ b/src/core/quote-outcomes.mjs @@ -56,12 +56,15 @@ export function deriveQuoteOutcomeRecords({ const expectedDelta = expectedDeltasByQuote.get(submission.quote_id) || null; if (!expectedDelta) continue; + const submittedTs = timestampValue(submission.submitted_at); + const matches = inventoryDeltas.filter((movement) => ( movementMatchesExpectedDelta({ movement, expectedDelta, - submittedAt: submission.submitted_at, attributionWindowMs, + submittedTs, + movementTs: movement.observed_ts, }) )); if (matches.length) candidatesByQuote.set(submission.quote_id, matches); @@ -152,6 +155,7 @@ export function deriveInventoryDeltas({ inventorySnapshots = [], activeAssetIds deltas.push({ movement_id: `${previous.observed_at}->${current.observed_at}`, observed_at: current.observed_at, + observed_ts: timestampValue(current.observed_at), previous_observed_at: previous.observed_at, inventory_id: current.inventory_id, previous_inventory_id: previous.inventory_id, @@ -343,21 +347,19 @@ function baseOutcomeRecord({ function movementMatchesExpectedDelta({ movement, expectedDelta, - submittedAt, + submittedTs, + movementTs, attributionWindowMs, }) { - const submittedTs = timestampValue(submittedAt); - const movementTs = timestampValue(movement.observed_at); if (!Number.isFinite(submittedTs) || !Number.isFinite(movementTs)) return false; if (movementTs < submittedTs) return false; if (movementTs - submittedTs > attributionWindowMs) return false; for (const [assetId, expected] of Object.entries(expectedDelta)) { - if (safeBigInt(movement.delta_units?.[assetId]) !== expected) return false; - } - for (const [assetId, actual] of Object.entries(movement.delta_units || {})) { - if (Object.prototype.hasOwnProperty.call(expectedDelta, assetId)) continue; - if (safeBigInt(actual) !== 0n) return false; + const actual = safeBigInt(movement.delta_units?.[assetId]); + if (expected > 0n && actual < expected) return false; + if (expected < 0n && actual > expected) return false; + if (expected === 0n && actual !== 0n) return false; } return true; diff --git a/src/lib/postgres.mjs b/src/lib/postgres.mjs index 55b896c..c5baa21 100644 --- a/src/lib/postgres.mjs +++ b/src/lib/postgres.mjs @@ -81,6 +81,7 @@ const REFRESHABLE_INTENT_REQUEST_OUTCOME_STATUSES = [ export function createPostgresPool({ connectionString }) { return new Pool({ connectionString, + max: 30, }); }