All checks were successful
deploy / deploy (push) Successful in 48s
Instead of fetching up to 50k inventory snapshots (~442MB), scope the query to only the time range of the current submission batch with a 15-minute buffer. For a typical 1-hour batch this drops from 50k rows to ~300 rows, well within the 1280Mi pod memory limit. The coalesced_at_idx on intent_inventory_snapshots covers the BETWEEN clause so this remains efficient. Proof: history-writer OOM kills from refreshQuoteOutcomes inventory fetch Assumptions: 15min buffer covers the attribution window for all submissions Still fake: heuristic gap outcomes may attribute trades imprecisely
43 lines
1.5 KiB
JavaScript
43 lines
1.5 KiB
JavaScript
import { createPostgresPool } from './src/lib/postgres.mjs';
|
|
import { deriveQuoteOutcomeRecords } from './src/core/quote-outcomes.mjs';
|
|
|
|
async function main() {
|
|
const pool = createPostgresPool({ connectionString: process.env.POSTGRES_URL });
|
|
|
|
const submissionsResult = await pool.query(`
|
|
SELECT event_id, observed_at, ingested_at, quote_id, payload
|
|
FROM trade_execution_results
|
|
WHERE payload->>'status' = 'submitted'
|
|
`);
|
|
const submissions = submissionsResult.rows;
|
|
|
|
const [commandsResult, decisionsResult, inventoryResult] = await Promise.all([
|
|
pool.query(`SELECT event_id, observed_at, ingested_at, quote_id, payload FROM execute_trade_commands`),
|
|
pool.query(`SELECT event_id, observed_at, ingested_at, quote_id, payload FROM trade_decisions`),
|
|
pool.query(`
|
|
SELECT event_id, observed_at, ingested_at, payload
|
|
FROM intent_inventory_snapshots
|
|
ORDER BY COALESCE(observed_at, ingested_at) DESC
|
|
LIMIT 15000
|
|
`),
|
|
]);
|
|
|
|
const btcAsset = { assetId: 'nep141:nbtc.bridge.near' };
|
|
const eureAsset = { assetId: 'nep141:eure.omft.near' };
|
|
|
|
console.log("Running derive...");
|
|
const records = deriveQuoteOutcomeRecords({
|
|
submissions,
|
|
commands: commandsResult.rows,
|
|
decisions: decisionsResult.rows,
|
|
inventorySnapshots: inventoryResult.rows,
|
|
btcAsset,
|
|
eureAsset,
|
|
now: new Date().toISOString()
|
|
});
|
|
|
|
const completed = records.filter(r => r.outcome_status === 'completed');
|
|
console.log("Found completed:", completed.length);
|
|
process.exit(0);
|
|
}
|
|
main().catch(console.error);
|