[REFACTOR]Zzim리스트 조회 시, User,Place,Photo,PostCategory 관련 N+1 문제 해결 #115
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.
📝 Work Description
Zzim 리스트 조회 시 발생했던 N+1 문제를 해결하기 위해, User, Place, Photo, PostCategory 조회 방식을 최적화했습니다.
기존에는 개별적으로 쿼리를 실행하여 데이터를 가져왔으나, 전역 Batch Size 설정 + IN 절 조회 방식으로 쿼리를 최적화하여 성능을 개선했습니다.
페이징을 고려하여 Fetch Join 대신 BatchSize 적용을 활용했습니다.
1. User, Place N+1 문제
2. Photo, PostCategory N+1 문제
⚙️ Issue
🔨 Changes
1. User, Place 조회 방식 변경:
전역 BatchSize 설정(hibernate.default_batch_fetch_size) 적용.
UserEntity와 PlaceEntity에 @batchsize(size = 100) 추가.
2. Photo, PostCategory IN 절 조회 적용:
기존에는 개별 Post별로 Photo와 PostCategory를 각각의 쿼리로 조회.
새로운 쿼리 메서드를 추가하여 IN 절로 다수의 Post에 대한 Photo와 PostCategory 데이터를 한 번에 가져옴.
결과적으로 Photo와 PostCategory 조회에서 발생하던 N+1 문제 해결.
3. Adapter 및 Port 인터페이스 수정:
4. Repository 수정: