[refactor/#148] 기존 단일 INSERT 쿼리 및 UPDATE 쿼리 대신 JDBC TEMPLATE를 활용한 BATCH 쿼리로 변경 #150
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.
❤️ 기능 설명
Spring Batch의 PostSummaryWriter에서 JPA
saveAll()대신 JDBC Batch 쿼리를 사용하여 게시글 요약 및 키워드 저장 시 DB 쿼리 수를 대폭 감소시켰습니다.주요 변경사항
1. JdbcBatchExecutor 유틸리티 생성 (src/main/java/com/techfork/global/util/JdbcBatchExecutor.java)
범용 JDBC Batch 실행 유틸리티 클래스 생성:
특징:
AS-IS (JPA):
TO-BE (JDBC Batch):
세부 구현:
updatePostSummaries(): 모든 게시글의 summary 필드를 배치 UPDATE
UPDATE posts SET summary = ? WHERE id = ?
deleteOldKeywords(): 모든 게시글의 기존 키워드를 배치 DELETE
DELETE FROM post_keywords WHERE post_id = ?
insertNewKeywords(): 모든 새 키워드를 배치 INSERT
INSERT INTO post_keywords (keyword, post_id) VALUES (?, ?)
entityManager.clear(): 영속성 컨텍스트 클리어로 추가 쿼리 방지
PostBatchWriter 클래스명 통일 (src/main/java/com/techfork/domain/source/batch/PostBatchWriter.java:25)
성능 개선 효과
100개 게시글, 각 5개 키워드 시:
부가 효과:
연결된 issue
close #148
✅ 체크리스트
참고 사이트
https://docs.spring.io/spring-framework/reference/6.2/data-access/jdbc/advanced.html