Refactor price loading logic in RevenueSection and SaleSection components: Replace for-loops with Promise.all for concurrent API requests, improving performance and responsiveness. This change enhances the handling of loading states and ensures better management of price data retrieval.

This commit is contained in:
Torsten Schulz (local)
2026-01-29 15:12:13 +01:00
parent 56ca92dd3c
commit a6f96e5500
2 changed files with 8 additions and 11 deletions

View File

@@ -294,12 +294,11 @@
}
},
async loadPricesForInventory() {
for (const item of this.inventory) {
const requests = this.inventory.map(async (item) => {
const itemKey = `${item.region.id}-${item.product.id}-${item.quality}`;
if (this.loadingPrices.has(itemKey)) continue;
if (this.loadingPrices.has(itemKey)) return;
this.loadingPrices.add(itemKey);
try {
// Aktueller Preis basierend auf sellCost
const currentPrice = item.product.sellCost || 0;
const { data } = await apiClient.get('/api/falukant/products/prices-in-cities', {
params: {
@@ -314,7 +313,8 @@
} finally {
this.loadingPrices.delete(itemKey);
}
}
});
await Promise.all(requests);
},
getCityPriceClass(branchType) {
if (branchType === 'store') return 'city-price-green';