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:
@@ -85,18 +85,12 @@ export async function fetchFromERP(): Promise<MuseumRecord[]> {
|
||||
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...`);
|
||||
|
||||
Reference in New Issue
Block a user