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