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
20 lines
917 B
JavaScript
20 lines
917 B
JavaScript
import { createPostgresPool } from './src/lib/postgres.mjs';
|
|
const pool = createPostgresPool({ connectionString: process.env.POSTGRES_URL });
|
|
|
|
async function main() {
|
|
console.log("Memory before:", process.memoryUsage().heapUsed / 1024 / 1024, "MB");
|
|
const result = await pool.query(`
|
|
SELECT event_id, observed_at, ingested_at, quote_id, jsonb_build_object('spendable', payload->'spendable', 'synced_at', payload->'synced_at') AS payload
|
|
FROM (
|
|
SELECT event_id, observed_at, ingested_at, quote_id, payload
|
|
FROM intent_inventory_snapshots
|
|
ORDER BY COALESCE(observed_at, ingested_at) DESC
|
|
LIMIT 50000
|
|
) recent_inventory_snapshots
|
|
ORDER BY COALESCE(observed_at, ingested_at) ASC
|
|
`);
|
|
console.log("Memory after fetch:", process.memoryUsage().heapUsed / 1024 / 1024, "MB");
|
|
console.log("Rows fetched:", result.rows.length);
|
|
process.exit(0);
|
|
}
|
|
main().catch(console.error);
|