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:
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user