Authored by mali

详情页性能优化

... ... @@ -109,7 +109,7 @@
<select id="selectLeastPricesByProductId" resultMap="BaseResultMap">
select * from (
select id, skup, storage_id, price, status, pre_sale_flag, region
from storage_price
from storage_price force index (`idx_storage_id_price`)
where status = 1 and product_id = #{productId} and is_hide = 0
order by storage_id,price asc limit 1000000
) a group by storage_id, pre_sale_flag, region
... ... @@ -272,11 +272,12 @@
</update>
<select id="selectInStockLeastPByProductId" resultMap="BaseResultMap">
select * from (
select id, skup, storage_id, price, status, pre_sale_flag, region
from storage_price
where status = 1 and product_id = #{productId} and is_hide = 0 and region = 0 and pre_sale_flag = 0
order by storage_id,price asc limit 1000000
) a group by storage_id
select t.id as id, t.skup as skup, t.storage_id as storage_id, t.price as price, t.status as status, t.pre_sale_flag as pre_sale_flag, t.region as region from storage_price t,
(select id from (select id ,storage_id
from storage_price FORCE INDEX (`idx_storage_id_price`)
where status = 1 and product_id = #{productId} and is_hide = 0 and region = 0 and pre_sale_flag = 0
order by storage_id,price asc limit 100000 )a
group by storage_id) b
where t.id = b.id
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -528,7 +528,7 @@ public class ProductServiceImpl implements ProductService {
if (productId == null) {
return new HashMap<>();
}
List<StoragePrice> storagePrices = storagePriceMapper.selectLeastPricesByProductId(productId);
List<StoragePrice> storagePrices = storagePriceService.selectLeastPricesByProductId(productId);
return storagePrices.stream().filter(price -> price.getPreSaleFlag() == 3).collect(Collectors.toMap(StoragePrice::getStorageId, StoragePrice::getPrice));
}
... ... @@ -547,7 +547,7 @@ public class ProductServiceImpl implements ProductService {
if (product == null) {
return new ArrayList<>();
}
List<StoragePrice> storagePrices = storagePriceMapper.selectLeastPricesByProductId(product.getId());
List<StoragePrice> storagePrices = storagePriceService.selectLeastPricesByProductId(product.getId());
List<StoragePrice> storagePrices1 = storagePrices.stream().filter(s -> s.getPreSaleFlag() == 0).collect(Collectors.toList());
Map<Integer, StoragePrice> storagePriceMap = storagePrices1.stream().collect(Collectors.toMap(StoragePrice::getStorageId, Function.identity(), BinaryOperator.minBy(Comparator.comparing(StoragePrice::getPrice))));
... ... @@ -1018,7 +1018,7 @@ public class ProductServiceImpl implements ProductService {
}
private Map<String, StoragePrice> getStorageLeastPriceInfo(Integer productId) {
List<StoragePrice> storagePrices = storagePriceMapper.selectLeastPricesByProductId(productId);
List<StoragePrice> storagePrices = storagePriceService.selectLeastPricesByProductId(productId);
return storagePrices.stream()
.collect(Collectors.toMap(s -> s.getStorageId() + "_" + s.getPreSaleFlag() + "_" + s.getRegion(), Function.identity()));
}
... ...
... ... @@ -104,4 +104,8 @@ public class StoragePriceService {
storagePriceUpdateEvent.setProductId(productId);
EventBusPublisher.publishEvent(storagePriceUpdateEvent);
}
public List<StoragePrice> selectLeastPricesByProductId(Integer productId) {
return storagePriceMapper.selectLeastPricesByProductId(productId);
}
}
... ...