Skip to content

Commit a9773d7

Browse files
committed
fix: 코드래빗 리뷰 반영
- 빈 청크 반환처리 추가 및 테스트 코드 추가 - 사용되지 않는 ContentRepository 메서드 제거
1 parent 43753fb commit a9773d7

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/main/java/com/codeit/team5/mopl/content/batch/writer/ContentItemWriter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public class ContentItemWriter implements ItemWriter<ContentWithMetaData> {
3535
public void write(Chunk<? extends ContentWithMetaData> chunk) {
3636
List<ContentWithMetaData> items = List.copyOf(chunk.getItems());
3737

38+
if (items.isEmpty()) {
39+
log.debug("[Batch] 빈 청크 수신 — 저장 생략");
40+
return;
41+
}
42+
3843
// 1. DB에 이미 존재하는 externalId 조회 후 신규 항목만 필터 (SELECT 1번)
3944
List<String> externalIds = items.stream()
4045
.map(item -> item.content().getExternalId())

src/main/java/com/codeit/team5/mopl/content/repository/ContentRepository.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ public interface ContentRepository extends JpaRepository<Content, UUID>, Content
1717
@EntityGraph(attributePaths = {"thumbnail", "stats", "contentTags", "contentTags.tag"})
1818
Optional<Content> findWithStatsAndTagsById(UUID id);
1919

20-
boolean existsBySourceAndExternalId(ContentSource source, String externalId);
21-
2220
@Query("SELECT c.externalId FROM Content c WHERE c.source = :source AND c.externalId IN :externalIds")
2321
Set<String> findExternalIdsBySourceAndExternalIdIn(
2422
@Param("source") ContentSource source,

src/test/java/com/codeit/team5/mopl/content/batch/writer/ContentItemWriterTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,17 @@ void write_deduplicatesAgainstDb() throws Exception {
9595
verify(contentRepository).saveAll(List.of(content2));
9696
}
9797

98+
@Test
99+
@DisplayName("빈 청크가 전달되면 예외 없이 즉시 반환한다")
100+
void write_emptyChunk_doesNothing() throws Exception {
101+
// when
102+
writer.write(new Chunk<>(List.of()));
103+
104+
// then
105+
verify(contentRepository, never()).findExternalIdsBySourceAndExternalIdIn(any(), anyList());
106+
verify(contentRepository, never()).saveAll(anyList());
107+
}
108+
98109
@Test
99110
@DisplayName("청크 내 모든 항목이 DB에 이미 존재하면 저장을 생략한다")
100111
void write_allExistingInDb_skipsAllSaves() throws Exception {

0 commit comments

Comments
 (0)