优化更新全部商品索引时的性能

This commit is contained in:
paulGao 2022-03-30 17:21:57 +08:00
parent c093261369
commit 210d56447c

View File

@ -431,6 +431,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
*/
@Override
public void updateEsGoodsIndexAllByList(BasePromotions promotion, String key) {
ThreadUtil.execAsync(() -> {
List<EsGoodsIndex> goodsIndices = new ArrayList<>();
//如果storeId不为空则表示是店铺活动
if (promotion.getStoreId() != null && !promotion.getStoreId().equals(PromotionTools.PLATFORM_ID)) {
@ -449,6 +450,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
}
List<String> skuIds = goodsIndices.stream().map(EsGoodsIndex::getId).collect(Collectors.toList());
this.updateEsGoodsIndexPromotions(skuIds, promotion, key);
});
}
@Override
@ -482,6 +484,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
*/
@Override
public void deleteEsGoodsPromotionByPromotionKey(String promotionsKey) {
ThreadUtil.execAsync(() -> {
BulkRequest bulkRequest = new BulkRequest();
for (EsGoodsIndex goodsIndex : this.goodsIndexRepository.findAll()) {
UpdateRequest updateRequest = this.removePromotionByPromotionKey(goodsIndex, promotionsKey);
@ -490,6 +493,7 @@ public class EsGoodsIndexServiceImpl extends BaseElasticsearchService implements
}
}
this.executeBulkUpdateRequest(bulkRequest);
});
}
/**