Authored by mali

详情页性能优化

@@ -109,7 +109,7 @@ @@ -109,7 +109,7 @@
109 <select id="selectLeastPricesByProductId" resultMap="BaseResultMap"> 109 <select id="selectLeastPricesByProductId" resultMap="BaseResultMap">
110 select * from ( 110 select * from (
111 select id, skup, storage_id, price, status, pre_sale_flag, region 111 select id, skup, storage_id, price, status, pre_sale_flag, region
112 - from storage_price 112 + from storage_price force index (`idx_storage_id_price`)
113 where status = 1 and product_id = #{productId} and is_hide = 0 113 where status = 1 and product_id = #{productId} and is_hide = 0
114 order by storage_id,price asc limit 1000000 114 order by storage_id,price asc limit 1000000
115 ) a group by storage_id, pre_sale_flag, region 115 ) a group by storage_id, pre_sale_flag, region
@@ -272,11 +272,12 @@ @@ -272,11 +272,12 @@
272 </update> 272 </update>
273 273
274 <select id="selectInStockLeastPByProductId" resultMap="BaseResultMap"> 274 <select id="selectInStockLeastPByProductId" resultMap="BaseResultMap">
275 - select * from (  
276 - select id, skup, storage_id, price, status, pre_sale_flag, region  
277 - from storage_price 275 + 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,
  276 + (select id from (select id ,storage_id
  277 + from storage_price FORCE INDEX (`idx_storage_id_price`)
278 where status = 1 and product_id = #{productId} and is_hide = 0 and region = 0 and pre_sale_flag = 0 278 where status = 1 and product_id = #{productId} and is_hide = 0 and region = 0 and pre_sale_flag = 0
279 - order by storage_id,price asc limit 1000000  
280 - ) a group by storage_id 279 + order by storage_id,price asc limit 100000 )a
  280 + group by storage_id) b
  281 + where t.id = b.id
281 </select> 282 </select>
282 </mapper> 283 </mapper>
@@ -528,7 +528,7 @@ public class ProductServiceImpl implements ProductService { @@ -528,7 +528,7 @@ public class ProductServiceImpl implements ProductService {
528 if (productId == null) { 528 if (productId == null) {
529 return new HashMap<>(); 529 return new HashMap<>();
530 } 530 }
531 - List<StoragePrice> storagePrices = storagePriceMapper.selectLeastPricesByProductId(productId); 531 + List<StoragePrice> storagePrices = storagePriceService.selectLeastPricesByProductId(productId);
532 return storagePrices.stream().filter(price -> price.getPreSaleFlag() == 3).collect(Collectors.toMap(StoragePrice::getStorageId, StoragePrice::getPrice)); 532 return storagePrices.stream().filter(price -> price.getPreSaleFlag() == 3).collect(Collectors.toMap(StoragePrice::getStorageId, StoragePrice::getPrice));
533 } 533 }
534 534
@@ -547,7 +547,7 @@ public class ProductServiceImpl implements ProductService { @@ -547,7 +547,7 @@ public class ProductServiceImpl implements ProductService {
547 if (product == null) { 547 if (product == null) {
548 return new ArrayList<>(); 548 return new ArrayList<>();
549 } 549 }
550 - List<StoragePrice> storagePrices = storagePriceMapper.selectLeastPricesByProductId(product.getId()); 550 + List<StoragePrice> storagePrices = storagePriceService.selectLeastPricesByProductId(product.getId());
551 List<StoragePrice> storagePrices1 = storagePrices.stream().filter(s -> s.getPreSaleFlag() == 0).collect(Collectors.toList()); 551 List<StoragePrice> storagePrices1 = storagePrices.stream().filter(s -> s.getPreSaleFlag() == 0).collect(Collectors.toList());
552 Map<Integer, StoragePrice> storagePriceMap = storagePrices1.stream().collect(Collectors.toMap(StoragePrice::getStorageId, Function.identity(), BinaryOperator.minBy(Comparator.comparing(StoragePrice::getPrice)))); 552 Map<Integer, StoragePrice> storagePriceMap = storagePrices1.stream().collect(Collectors.toMap(StoragePrice::getStorageId, Function.identity(), BinaryOperator.minBy(Comparator.comparing(StoragePrice::getPrice))));
553 553
@@ -1018,7 +1018,7 @@ public class ProductServiceImpl implements ProductService { @@ -1018,7 +1018,7 @@ public class ProductServiceImpl implements ProductService {
1018 } 1018 }
1019 1019
1020 private Map<String, StoragePrice> getStorageLeastPriceInfo(Integer productId) { 1020 private Map<String, StoragePrice> getStorageLeastPriceInfo(Integer productId) {
1021 - List<StoragePrice> storagePrices = storagePriceMapper.selectLeastPricesByProductId(productId); 1021 + List<StoragePrice> storagePrices = storagePriceService.selectLeastPricesByProductId(productId);
1022 return storagePrices.stream() 1022 return storagePrices.stream()
1023 .collect(Collectors.toMap(s -> s.getStorageId() + "_" + s.getPreSaleFlag() + "_" + s.getRegion(), Function.identity())); 1023 .collect(Collectors.toMap(s -> s.getStorageId() + "_" + s.getPreSaleFlag() + "_" + s.getRegion(), Function.identity()));
1024 } 1024 }
@@ -104,4 +104,8 @@ public class StoragePriceService { @@ -104,4 +104,8 @@ public class StoragePriceService {
104 storagePriceUpdateEvent.setProductId(productId); 104 storagePriceUpdateEvent.setProductId(productId);
105 EventBusPublisher.publishEvent(storagePriceUpdateEvent); 105 EventBusPublisher.publishEvent(storagePriceUpdateEvent);
106 } 106 }
  107 +
  108 + public List<StoragePrice> selectLeastPricesByProductId(Integer productId) {
  109 + return storagePriceMapper.selectLeastPricesByProductId(productId);
  110 + }
107 } 111 }