Add batch processing for product price retrieval: Implement getProductPricesInCitiesBatch method in FalukantService for handling multiple product price requests in a single API call. Update FalukantController and router to support new endpoint, and refactor RevenueSection and SaleSection components to utilize batch processing for improved performance and reduced API calls.
This commit is contained in:
@@ -293,27 +293,26 @@
|
||||
}
|
||||
},
|
||||
async loadPricesForInventory() {
|
||||
const requests = this.inventory.map(async (item) => {
|
||||
const itemKey = `${item.region.id}-${item.product.id}-${item.quality}`;
|
||||
if (this.loadingPrices.has(itemKey)) return;
|
||||
this.loadingPrices.add(itemKey);
|
||||
try {
|
||||
const currentPrice = item.product.sellCost || 0;
|
||||
const { data } = await apiClient.get('/api/falukant/products/prices-in-cities', {
|
||||
params: {
|
||||
productId: item.product.id,
|
||||
currentPrice: currentPrice
|
||||
}
|
||||
});
|
||||
item.betterPrices = data || [];
|
||||
} catch (error) {
|
||||
console.error(`Error loading prices for item ${itemKey}:`, error);
|
||||
item.betterPrices = [];
|
||||
} finally {
|
||||
this.loadingPrices.delete(itemKey);
|
||||
if (this.inventory.length === 0) return;
|
||||
const currentRegionId = this.inventory[0]?.region?.id ?? null;
|
||||
const items = this.inventory.map(item => ({
|
||||
productId: item.product.id,
|
||||
currentPrice: item.product.sellCost || 0
|
||||
}));
|
||||
try {
|
||||
const { data } = await apiClient.post('/api/falukant/products/prices-in-cities-batch', {
|
||||
currentRegionId,
|
||||
items
|
||||
});
|
||||
for (const item of this.inventory) {
|
||||
item.betterPrices = data && data[item.product.id] ? data[item.product.id] : [];
|
||||
}
|
||||
});
|
||||
await Promise.all(requests);
|
||||
} catch (error) {
|
||||
console.error('Error loading prices for inventory:', error);
|
||||
for (const item of this.inventory) {
|
||||
item.betterPrices = [];
|
||||
}
|
||||
}
|
||||
},
|
||||
getCityPriceClass(branchType) {
|
||||
if (branchType === 'store') return 'city-price-green';
|
||||
|
||||
Reference in New Issue
Block a user