Open
Conversation
|
미션 너무 잘 수행하신 것 같습니다! 수고하셨습니다~! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎋 작업중인 브랜치
#4 , feat/5week-jpql
⚡️ 작업동기
1. JPA와 영속성 컨텍스트 (Persistence Context)의 핵심 이해
JPA는 객체와 RDB 간의 패러다임 불일치를 해소하는 ORM 기술이며, 그 중심에는 영속성 컨텍스트가 있습니다.
UPDATE쿼리를 생성하고 반영합니다.2. Spring Data JPA를 통한 데이터 접근 및 쿼리 전략
Spring Data JPA는
Repository인터페이스를 사용하여 DB 접근을 간소화할 수 있습니다. 이번 미션에서는@Query어노테이션으로 JPQL을 직접 작성하는 방식을 사용했습니다.save():JpaRepository상속으로 기본적인 CRUD가 제공됩니다.reviewRepository.save(review)호출은 엔티티를 영속화하고, 트랜잭션 커밋 시점에INSERT쿼리를 자동 실행합니다.@Query와 JPQL: 복잡한 조회 조건이나 커스터마이징을 위해@Query를 사용하며, 테이블이 아닌 엔티티 객체를 대상으로 쿼리하는 JPQL을 작성했습니다.findMemberById메서드는@Query("select m from Member m where m.id = :memberId")를 통해 특정 ID의Member엔티티를 조회합니다.3. 성능 최적화 전략: N+1 문제와 커서 페이징
효율적인 데이터 조회와 대용량 처리를 위해 다음과 같은 최적화 전략을 적용했습니다.
① N+1 문제 해결을 위한
join fetch(페치 조인)findMemberMissions와findAvailableMissions쿼리에서join fetch를 사용하여 연관된 엔티티 (mm.mission,m.store)를 하나의 쿼리로 함께 조회함으로써, N+1 문제를 근본적으로 해결하고 성능을 최적화했습니다.② 커서 기반 페이징
WHERE mm.id < :cursor와 같이 이전에 조회된 마지막 레코드의 ID를 기준으로 다음 페이지를 조회하도록 구현했습니다.MissionService에서cursor가null인 경우Long.MAX_VALUE를 사용하여 첫 페이지부터 최신 데이터를 조회하도록 처리했습니다.③ 비즈니스 로직 구현
findMemberMissions에서order by case when mm.status = 'CHALLENGING' then 1 else 2 end를 사용하여 진행 중인 미션을 완료된 미션보다 우선적으로 정렬하는 로직을 JPQL 내에서 구현했습니다.findAvailableMissions에서 서브 쿼리를 이용해and m.id not in (...)조건을 적용하여, 이미 도전 중인 미션은 목록에서 제외하는 복잡한 필터링을 구현했습니다. 추후 QueryDSL과 같이 쿼리 빌더 라이브러리를 사용해서 리팩토링을 진행할수도 있겠습니다.Check List