Post

TroubleShooting_Too long to get main page

โœ… Takes too long to get main page

  • In developer tools takes 3.83 seconds Screenshot 2024-07-11 at 23 22 13

  • In HTTPS postman 4s 25ms Screenshot 2024-07-11 at 23 23 07

  • In Localhost postman takes more than 9 minutes!!! Screenshot 2024-07-17 at 23 11 01

๐Ÿ”ต 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.

  • Developer tools image

  • Localhost Postman

    • 9mins โžก๏ธ 2seconds

    Screenshot 2024-07-17 at 23 16 58

  • HTTPS Postman 3.55 seconds Screenshot 2024-07-17 at 23 21 00

  • HTTPS Developer tools 28ms Screenshot 2024-07-17 at 23 22 09

This post is licensed under CC BY 4.0 by the author.