스프링부트 쇼핑몰 프로젝트 | 8 장바구니, 배포

Yunny.Log ·2022년 6월 6일
0

Spring Boot

목록 보기
67/80
post-thumbnail

N+1 문제 해결하기 (대댓글 문제)

내가 하고 싶던 것 :
분류1을 불러올 때 분류1에 딸린 분류2를 가져오고 싶음

리팩토링 전

List<Classification2> findByClassification1(Classification1 classification1);
Hibernate: select classifica0_.id as id1_6_0_, classifica1_.id as id1_7_1_, classifica0_.last as last2_6_0_, classifica0_.name as name3_6_0_, classifica1_.classification1_id as classification4_7_1_, classifica1_.last as last2_7_1_, classifica1_.name as name3_7_1_, classifica1_.classification1_id as classification4_7_0__, classifica1_.id as id1_7_0__ from classification1 classifica0_ inner join classification2 classifica1_ on classifica0_.id=classifica1_.classification1_id
Hibernate: select classifica0_.id as id1_7_, classifica0_.classification1_id as classification4_7_, classifica0_.last as last2_7_, classifica0_.name as name3_7_ from classification2 classifica0_ where classifica0_.classification1_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_7_, classifica0_.classification1_id as classification4_7_, classifica0_.last as last2_7_, classifica0_.name as name3_7_ from classification2 classifica0_ where classifica0_.classification1_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_7_, classifica0_.classification1_id as classification4_7_, classifica0_.last as last2_7_, classifica0_.name as name3_7_ from classification2 classifica0_ where classifica0_.classification1_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_7_, classifica0_.classification1_id as classification4_7_, classifica0_.last as last2_7_, classifica0_.name as name3_7_ from classification2 classifica0_ where classifica0_.classification1_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_7_, classifica0_.classification1_id as classification4_7_, classifica0_.last as last2_7_, classifica0_.name as name3_7_ from classification2 classifica0_ where classifica0_.classification1_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_7_, classifica0_.classification1_id as classification4_7_, classifica0_.last as last2_7_, classifica0_.name as name3_7_ from classification2 classifica0_ where classifica0_.classification1_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_7_, classifica0_.classification1_id as classification4_7_, classifica0_.last as last2_7_, classifica0_.name as name3_7_ from classification2 classifica0_ where classifica0_.classification1_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_7_, classifica0_.classification1_id as classification4_7_, classifica0_.last as last2_7_, classifica0_.name as name3_7_ from classification2 classifica0_ where classifica0_.classification1_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_7_, classifica0_.classification1_id as classification4_7_, classifica0_.last as last2_7_, classifica0_.name as name3_7_ from classification2 classifica0_ where classifica0_.classification1_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_7_, classifica0_.classification1_id as classification4_7_, classifica0_.last as last2_7_, classifica0_.name as name3_7_ from classification2 classifica0_ where classifica0_.classification1_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?

리팩토링 후

@Query("select c from Classification1 c join fetch c.classification2List ")
        List<Classification1> findAllByClassification1();
Hibernate: select classifica0_.id as id1_6_, classifica0_.last as last2_6_, classifica0_.name as name3_6_ from classification1 classifica0_
Hibernate: select classifica0_.id as id1_7_, classifica0_.classification1_id as classification4_7_, classifica0_.last as last2_7_, classifica0_.name as name3_7_ from classification2 classifica0_ where classifica0_.classification1_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_7_, classifica0_.classification1_id as classification4_7_, classifica0_.last as last2_7_, classifica0_.name as name3_7_ from classification2 classifica0_ where classifica0_.classification1_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_7_, classifica0_.classification1_id as classification4_7_, classifica0_.last as last2_7_, classifica0_.name as name3_7_ from classification2 classifica0_ where classifica0_.classification1_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_7_, classifica0_.classification1_id as classification4_7_, classifica0_.last as last2_7_, classifica0_.name as name3_7_ from classification2 classifica0_ where classifica0_.classification1_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?
Hibernate: select classifica0_.id as id1_7_, classifica0_.classification1_id as classification4_7_, classifica0_.last as last2_7_, classifica0_.name as name3_7_ from classification2 classifica0_ where classifica0_.classification1_id=?
Hibernate: select classifica0_.id as id1_8_, classifica0_.classification2_id as classification4_8_, classifica0_.last as last2_8_, classifica0_.name as name3_8_ from classification3 classifica0_ where classifica0_.classification2_id=?

배포

EC2 인스턴스 연결, RDS 연결, 도메인 연결, NGINX, 보안 설정

  • 워크벤치에서 데이터베이스 따로 관리 가능, 편리
  • 도메인 연결을 통해서 접속 용이
  • http에서 https로 nginx가 리디렉트 잘 해줌

한계

  • git push 할 때마다 자동적으로 안됨
  • 배포 할 때마다 jdk 깔고, 이것저것 깔고,, 여러 환경에 쉽게 배포가 어려움

하고 싶은 배포 .. (공부 NEEDED)

1) CI, CD (트래비스) & 도커 컨테이너를 통한 배포

0개의 댓글