TroubleShooting_Too long to get main page
โ Takes too long to get main page
๐ต Tryout 1. Move update code to each service.
First, the update code was inside the for loop.
Thus, making the update for each product each time calling a product.
This was considered to be so inefficient.
Moved the update code outside the for loop.
๐๐ป Before
1
2
3
4
5
6
7
8
9
10
11
public List<productListQueryDto> getProductListQueryDto(List<Product> productList) {
List<productListQueryDto> plqdList = new ArrayList<>();
for (Product product : productList) {
productRepository.updateProductSales(); //๐ด
productRepository.updateReviewAvg(); //๐ด
int productLike=productRepository.countLikesByProductId(product.getProductId());
productListQueryDto plqd = productListQueryDto.builder()
.product_id(product.getProductId())
}
๐๐ป After
1
2
3
4
5
6
7
8
9
10
11
12
public List<productListQueryDto> getProductListQueryDto(List<Product> productList) {
List<productListQueryDto> plqdList = new ArrayList<>();
productRepository.updateProductSales(); //๐ตoutside for loop
productRepository.updateReviewAvg();
for (Product product : productList) {
int productLike=productRepository.countLikesByProductId(product.getProductId());
productListQueryDto plqd = productListQueryDto.builder()
.product_id(product.getProductId())
}
}
๐ข Result
Just by doing this, the time for loading main page reduced from 3 seconds to 1.
This post is licensed under CC BY 4.0 by the author.