TR1LL1ON / TR1LL1ON_BE

🌟 숙박 예약 서비스 [트릴리언] 🌟
https://www.tr1ll1on.site/
1 stars 3 forks source link

Refactor: 리뷰 조회 리팩토링 #96

Closed yurim0628 closed 11 months ago

yurim0628 commented 11 months ago

숙소 전체 리뷰 조회 / 사용자 전체 리뷰 조회 성능 개선

조회 속도 향상에 목적을 두고 리팩토링 진행하였습니다.

자세한 구현 내용은 블로그 를 통해 확인해주시면 감사하겠습니다.

1. 숙소 전체 리뷰 조회 : 497ms -> 181ms

스크린샷 2023-12-04 15 56 03 스크린샷 2023-12-05 02 24 32

조회 한 번당 발생하는 쿼리문은 다음과 같습니다.

Hibernate: 
    select
        a1_0.accommodation_id,
        a1_0.address,
        a1_0.area_code,
        a1_0.category_id,
        a1_0.accommodation_facility_id,
        a1_0.latitude,
        a1_0.longitude,
        a1_0.name,
        a1_0.phone,
        p1_0.accommodation_id,
        p1_0.product_id,
        p1_0.check_in_time,
        p1_0.check_out_time,
        p1_0.count,
        p1_0.maximum_number,
        p1_0.name,
        p1_0.product_facility_id,
        p1_0.standard_number 
    from
        accommodation a1_0 
    join
        product p1_0 
            on a1_0.accommodation_id=p1_0.accommodation_id 
    where
        a1_0.accommodation_id=?
Hibernate: 
    select
        r1_0.product_id,
        r1_0.review_id,
        r1_0.content,
        r1_0.review_date,
        r1_0.score,
        u1_0.user_id,
        u1_0.authority,
        u1_0.cart_id,
        u1_0.email,
        u1_0.name,
        u1_0.password 
    from
        review r1_0 
    left join
        user u1_0 
            on u1_0.user_id=r1_0.user_id 
    where
        r1_0.product_id in(?,?,?,?)
Hibernate: 
    select
        p1_0.product_id,
        p1_0.product_image_id,
        p1_0.image_url 
    from
        product_image p1_0 
    where
        p1_0.product_id in(?,?,?,?)

2. 사용자 전체 리뷰 조회 : 1261ms -> 183ms

스크린샷 2023-12-04 15 42 06 스크린샷 2023-12-04 15 43 28

조회 한 번당 발생하는 쿼리문은 다음과 같습니다.

Hibernate: 
    select
        u1_0.user_id,
        u1_0.authority,
        u1_0.cart_id,
        u1_0.email,
        u1_0.name,
        u1_0.password 
    from
        user u1_0 
    where
        u1_0.user_id=?
Hibernate: 
    select
        r1_0.review_id,
        r1_0.content,
        o1_0.order_item_id,
        o1_0.end_date,
        o1_0.order_id,
        o1_0.person_number,
        o1_0.price,
        o1_0.product_id,
        o1_0.review_written,
        o1_0.start_date,
        p1_0.product_id,
        a1_0.accommodation_id,
        a1_0.address,
        a1_0.area_code,
        a1_0.category_id,
        a1_0.accommodation_facility_id,
        a1_0.latitude,
        a1_0.longitude,
        a1_0.name,
        a1_0.phone,
        p1_0.check_in_time,
        p1_0.check_out_time,
        p1_0.count,
        p1_0.maximum_number,
        p1_0.name,
        p1_0.product_facility_id,
        p1_0.standard_number,
        r1_0.review_date,
        r1_0.score,
        r1_0.user_id 
    from
        review r1_0 
    join
        product p1_0 
            on p1_0.product_id=r1_0.product_id 
    join
        accommodation a1_0 
            on a1_0.accommodation_id=p1_0.accommodation_id 
    join
        order_item o1_0 
            on o1_0.order_item_id=r1_0.order_item_id 
    where
        r1_0.user_id=?
Hibernate: 
    select
        p1_0.product_id,
        p1_0.product_image_id,
        p1_0.image_url 
    from
        product_image p1_0 
    where
        p1_0.product_id in(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)

데이터 양이 많아질수록 성능 향상에 더 효과적인 것 같습니다.