fix: fetch ERP months sequentially to avoid 500 errors

The ERP API can't handle concurrent requests — switch from batched
parallel (4 at a time) to sequential fetching.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
fahed
2026-03-26 16:59:21 +03:00
parent ea71e54058
commit 18821fd560

View File

@@ -85,18 +85,12 @@ export async function fetchFromERP(): Promise<MuseumRecord[]> {
console.log('Fetching from ERP API via proxy...'); console.log('Fetching from ERP API via proxy...');
const months = generateMonthBoundaries(2024, 1); const months = generateMonthBoundaries(2024, 1);
// Fetch all months in parallel (batched in groups of 4 to avoid overwhelming) // Fetch months sequentially — the ERP API doesn't handle concurrent requests well
const batchSize = 4;
const allSales: ERPSaleRecord[] = []; const allSales: ERPSaleRecord[] = [];
for (let i = 0; i < months.length; i += batchSize) { for (const [start, end] of months) {
const batch = months.slice(i, i + batchSize); const chunk = await fetchChunk(start, end);
const results = await Promise.all( allSales.push(...chunk);
batch.map(([start, end]) => fetchChunk(start, end))
);
for (const chunk of results) {
allSales.push(...chunk);
}
} }
console.log(`Fetched ${allSales.length} transactions, aggregating...`); console.log(`Fetched ${allSales.length} transactions, aggregating...`);