Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] 족보 상세보기에서 식당 정렬순 족보에 추가한 순으로 변경 #167

Merged
merged 6 commits into from
Aug 26, 2024

Conversation

PicturePark1101
Copy link
Contributor

@PicturePark1101 PicturePark1101 commented Aug 14, 2024

Related Issue 📌

close #166

Description ✔️

  • 족보 상세보기에서 식당 정렬순 족보에 추가한 순으로 변경

To Reviewers

  1. Favorite과 FavoriteStore [left join fetch]로 가져옴

(족보에 가게 있다면)
2. favoriestore와 store 그냥 join 함 - 이미 1번으로 인해 FavoriteStore 영속성에 있으므로 굳이 fetch join 할 필요없음

    @Query("select s from Store s join FavoriteStore fs on s.id = fs.store.id where fs in :favoriteStores and s.isDeleted = false order by fs.id desc ")
    List<Store> findAllByIdsAndIsDeletedIsFalseOrderByFavoriteStoreId(@Param("favoriteStores") List<FavoriteStore> favoriteStores);
  1. store_image는 batch로 in쿼리로 가져옴

<족보에 가게 있을 경우>

Hibernate: 
    select
        f1_0.favorite_id,
        f1_0.created_at,
        f1_0.detail,
        fs1_0.favorite_id,
        fs1_0.favorite_store_id,
        fs1_0.store_id,
        f1_0.image_type,
        f1_0.name,
        f1_0.updated_at,
        f1_0.user_id 
    from
        favorite f1_0 
    left join
        favorite_store fs1_0 
            on f1_0.favorite_id=fs1_0.favorite_id 
    where
        f1_0.favorite_id=?
Hibernate: 
    select
        s1_0.store_id,
        s1_0.address,
        s1_0.category,
        s1_0.created_at,
        s1_0.heart_count,
        s1_0.is_deleted,
        s1_0.lowest_price,
        s1_0.name,
        s1_0.latitude,
        s1_0.longitude,
        s1_0.updated_at 
    from
        store s1_0 
    join
        favorite_store fs1_0 
            on s1_0.store_id=fs1_0.store_id 
    where
        fs1_0.favorite_store_id in (?, ?, ?, ?, ?) 
        and s1_0.is_deleted=false 
    order by
        fs1_0.favorite_store_id desc
Hibernate: 
    select
        i1_0.store_id,
        i1_0.store_image_id,
        i1_0.created_at,
        i1_0.image_url 
    from
        store_image i1_0 
    where
        i1_0.store_id = any (?)

<족보에 가게 없을 경우>

Hibernate: 
    select
        f1_0.favorite_id,
        f1_0.created_at,
        f1_0.detail,
        fs1_0.favorite_id,
        fs1_0.favorite_store_id,
        fs1_0.store_id,
        f1_0.image_type,
        f1_0.name,
        f1_0.updated_at,
        f1_0.user_id 
    from
        favorite f1_0 
    left join
        favorite_store fs1_0 
            on f1_0.favorite_id=fs1_0.favorite_id 
    where
        f1_0.favorite_id=?


Copy link
Member

@kgy1008 kgy1008 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

개인적인 궁금증인데, 정렬하기 위해 쿼리를 따로 생성하지 않고 FavoriteStore 엔티티의 필드에 @orderby 어노테이션을 이용해서 정렬을 간편화할 수 있는데 이런 방식을 선택한 이유가 무엇인가요?

@@ -50,7 +51,7 @@ private List<Store> findStoresInFavorite(final Favorite favorite){
if (favoriteHasNoStore(favorite)) {
return new ArrayList<>();
}
return storeFinder.findAllByIdsWhereDeletedIsFalseOrderByCreatedAtDes(favorite.getFavoriteStores().stream().map(fs -> fs.getStore().getId()).toList());
return storeFinder.findAllByIdsWhereDeletedIsFalseOrderByFavoriteStoreId(favorite.getFavoriteStores());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

함수명 findAllByFavoriteStoreWhereDeletedIsFalse로 변경하는 것은 어떨까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반영했습니당 👍

@PicturePark1101
Copy link
Contributor Author

개인적인 궁금증인데, 정렬하기 위해 쿼리를 따로 생성하지 않고 FavoriteStore 엔티티의 필드에 @orderby 어노테이션을 이용해서 정렬을 간편화할 수 있는데 이런 방식을 선택한 이유가 무엇인가요?

store은 페이징 때문에 in 쿼리로 가져와야하기 때문에 이렇게 했습니당
그런데 말씀해주신 것처럼 Favorite이랑 FavoriteStore 같이 가져올 때 정렬하면 store을 그 순서대로 가져올 수 있을지 모르겠네요 지금 레디스 억까당하고 있어서 이 현상 해결하고 테스트해보겠습니다!

@PicturePark1101 PicturePark1101 merged commit 0a94942 into develop Aug 26, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feat] 족보 상세보기에서 식당 리스트 정렬값 식당에 추가된 순으로 정렬
2 participants