아이템 디테일 조회 API - 가격 제안 표시 포함
아이템 디테일 조회 API - 가격 제안 표시 포함
- 조회 쿼리 (수정 전)
- querydsl
return queryFactory.select(item, new CaseBuilder().when(userItem.user.id.eq(userId)).then(1L).otherwise(0L).sum().as("isExistOfLike"), new CaseBuilder().when(pricePropose.user.id.eq(userId)).then(1L).otherwise(0L).sum().as("isExistOfPricePropose") ) .from(item) .leftJoin(userItem).on(userItem.item.eq(item)) .leftJoin(pricePropose).on(pricePropose.item.eq(item)) .where(item.id.eq(itemId)) .groupBy(item) .fetchOne();
- 결과 출력
03:36:48.120 [http-nio-8080-exec-2] DEBUG org.hibernate.SQL - select count(*) as col_0_0_ from user user0_ where user0_.user_id=? 03:36:48.194 [http-nio-8080-exec-2] DEBUG org.hibernate.SQL - select item0_.item_id as col_0_0_, sum(case when useritem1_.user_id=? then ? else 0 end) as col_1_0_, sum(case when pricepropo2_.user_id=? then ? else 0 end) as col_2_0_, item0_.item_id as item_id1_6_, item0_.category_item_id as categor12_6_, item0_.created_at as created_2_6_, item0_.description as descript3_6_, item0_.grade_status as grade_st4_6_, item0_.idol_member_id as idol_me13_6_, item0_.likes_item_count as likes_it5_6_, item0_.name as name6_6_, item0_.price as price7_6_, item0_.trade_status as trade_st8_6_, item0_.trade_type as trade_ty9_6_, item0_.updated_at as updated10_6_, item0_.user_id as user_id14_6_, item0_.views as views11_6_ from item item0_ left outer join user_item useritem1_ on ( useritem1_.item_id=item0_.item_id ) left outer join price_propose pricepropo2_ on ( pricepropo2_.item_id=item0_.item_id ) inner join idol_member idolmember3_ on ( item0_.idol_member_id=idolmember3_.idol_member_id ) inner join idol_group idolgroup4_ on ( idolmember3_.idol_group_id=idolgroup4_.idol_group_id ) inner join category_item categoryit5_ on ( item0_.category_item_id=categoryit5_.category_item_id ) inner join user user6_ on ( item0_.user_id=user6_.user_id ) where item0_.item_id=? group by item0_.item_id 03:36:48.219 [http-nio-8080-exec-2] DEBUG org.hibernate.SQL - select user0_.user_id as user_id1_10_0_, user0_.created_at as created_2_10_0_, user0_.email as email3_10_0_, user0_.image_url as image_ur4_10_0_, user0_.last_login_at as last_log5_10_0_, user0_.nick_name as nick_nam6_10_0_, user0_.phone_number as phone_nu7_10_0_, user0_.role as role8_10_0_ from user user0_ where user0_.user_id=? 03:36:48.224 [http-nio-8080-exec-2] DEBUG org.hibernate.SQL - select images0_.item_id as item_id5_5_0_, images0_.image_id as image_id1_5_0_, images0_.image_id as image_id1_5_1_, images0_.item_id as item_id5_5_1_, images0_.origin_name as origin_n2_5_1_, images0_.upload_name as upload_n3_5_1_, images0_.url as url4_5_1_ from image images0_ where images0_.item_id=? 03:36:48.227 [http-nio-8080-exec-2] DEBUG org.hibernate.SQL - select idolmember0_.idol_member_id as idol_mem1_4_0_, idolmember0_.idol_group_id as idol_gro4_4_0_, idolmember0_.image_url as image_ur2_4_0_, idolmember0_.name as name3_4_0_ from idol_member idolmember0_ where idolmember0_.idol_member_id=? 03:36:48.229 [http-nio-8080-exec-2] DEBUG org.hibernate.SQL - select idolgroup0_.idol_group_id as idol_gro1_3_0_, idolgroup0_.eng_name as eng_name2_3_0_, idolgroup0_.image_url as image_ur3_3_0_, idolgroup0_.kor_name as kor_name4_3_0_, idolgroup0_.name as name5_3_0_, idolgroup0_.voted_count as voted_co6_3_0_ from idol_group idolgroup0_ where idolgroup0_.idol_group_id=? 03:36:48.230 [http-nio-8080-exec-2] DEBUG org.hibernate.SQL - select categoryit0_.category_item_id as category1_2_0_, categoryit0_.name as name2_2_0_ from category_item categoryit0_ where categoryit0_.category_item_id=?
- 수정 후
- querydsl
return queryFactory.select(item, new CaseBuilder().when(userItem.user.id.eq(userId)).then(1L).otherwise(0L).sum().as("isExistOfLike"), new CaseBuilder().when(pricePropose.user.id.eq(userId)).then(1L).otherwise(0L).sum().as("isExistOfPricePropose"), idolMember, idolGroup, categoryItem, user ) .from(item) .leftJoin(userItem).on(userItem.item.eq(item)).fetchJoin() .leftJoin(pricePropose).on(pricePropose.item.eq(item)).fetchJoin() .join(idolMember).on(item.idolMember.eq(idolMember)).fetchJoin() .join(idolGroup).on(idolMember.idolGroup.eq(idolGroup)).fetchJoin() .join(categoryItem).on(item.categoryItem.eq(categoryItem)).fetchJoin() .join(user).on(item.user.eq(user)).fetchJoin() .where(item.id.eq(itemId)) .groupBy(item, idolMember, idolGroup ,categoryItem ,user) .fetchOne();
- 결과 출력
03:47:53.994 [http-nio-8080-exec-2] DEBUG org.hibernate.SQL - select count(*) as col_0_0_ from user user0_ where user0_.user_id=? 03:47:54.059 [http-nio-8080-exec-2] DEBUG org.hibernate.SQL - select item0_.item_id as col_0_0_, sum(case when useritem1_.user_id=? then ? else 0 end) as col_1_0_, sum(case when pricepropo2_.user_id=? then ? else 0 end) as col_2_0_, idolmember3_.idol_member_id as col_3_0_, idolgroup4_.idol_group_id as col_4_0_, categoryit5_.category_item_id as col_5_0_, user6_.user_id as col_6_0_, item0_.item_id as item_id1_6_0_, idolmember3_.idol_member_id as idol_mem1_4_1_, idolgroup4_.idol_group_id as idol_gro1_3_2_, categoryit5_.category_item_id as category1_2_3_, user6_.user_id as user_id1_10_4_, item0_.category_item_id as categor12_6_0_, item0_.created_at as created_2_6_0_, item0_.description as descript3_6_0_, item0_.grade_status as grade_st4_6_0_, item0_.idol_member_id as idol_me13_6_0_, item0_.likes_item_count as likes_it5_6_0_, item0_.name as name6_6_0_, item0_.price as price7_6_0_, item0_.trade_status as trade_st8_6_0_, item0_.trade_type as trade_ty9_6_0_, item0_.updated_at as updated10_6_0_, item0_.user_id as user_id14_6_0_, item0_.views as views11_6_0_, idolmember3_.idol_group_id as idol_gro4_4_1_, idolmember3_.image_url as image_ur2_4_1_, idolmember3_.name as name3_4_1_, idolgroup4_.eng_name as eng_name2_3_2_, idolgroup4_.image_url as image_ur3_3_2_, idolgroup4_.kor_name as kor_name4_3_2_, idolgroup4_.name as name5_3_2_, idolgroup4_.voted_count as voted_co6_3_2_, categoryit5_.name as name2_2_3_, user6_.created_at as created_2_10_4_, user6_.email as email3_10_4_, user6_.image_url as image_ur4_10_4_, user6_.last_login_at as last_log5_10_4_, user6_.nick_name as nick_nam6_10_4_, user6_.phone_number as phone_nu7_10_4_, user6_.role as role8_10_4_ from item item0_ left outer join user_item useritem1_ on ( useritem1_.item_id=item0_.item_id ) left outer join price_propose pricepropo2_ on ( pricepropo2_.item_id=item0_.item_id ) inner join idol_member idolmember3_ on ( item0_.idol_member_id=idolmember3_.idol_member_id ) inner join idol_group idolgroup4_ on ( idolmember3_.idol_group_id=idolgroup4_.idol_group_id ) inner join category_item categoryit5_ on ( item0_.category_item_id=categoryit5_.category_item_id ) inner join user user6_ on ( item0_.user_id=user6_.user_id ) where item0_.item_id=? group by item0_.item_id , idolmember3_.idol_member_id , idolgroup4_.idol_group_id , categoryit5_.category_item_id , user6_.user_id 03:47:54.079 [http-nio-8080-exec-2] DEBUG org.hibernate.SQL - select images0_.item_id as item_id5_5_0_, images0_.image_id as image_id1_5_0_, images0_.image_id as image_id1_5_1_, images0_.item_id as item_id5_5_1_, images0_.origin_name as origin_n2_5_1_, images0_.upload_name as upload_n3_5_1_, images0_.url as url4_5_1_ from image images0_ where images0_.item_id=?