Skip to content

성능 개선: ReviewCategoryOptionTop3Service에서 일괄 저장 사용 #155

@coderabbitai

Description

@coderabbitai

개요

ReviewCategoryOptionTop3Service.recalculateTop3ByRoute 메서드에서 개별 저장 대신 일괄 저장을 사용하여 성능을 개선할 수 있습니다.

현재 상황

현재 코드는 forEach를 사용하여 각 엔티티를 개별적으로 저장하고 있습니다:

countResults.stream()
    .limit(3)
    .map(row -> ReviewCategoryOptionTop3Entity.builder()
        .selectionCount(((Number)row[1]).intValue())
        .route(route)
        .categoryOption((CategoryOptionEntity)row[0])
        .build())
    .forEach(reviewCategoryOptionTop3Repository::save);

제안된 개선사항

saveAll을 사용하여 일괄 저장으로 성능을 향상시킬 수 있습니다:

List<ReviewCategoryOptionTop3Entity> top3Entities = countResults.stream()
    .limit(3)
    .map(row -> ReviewCategoryOptionTop3Entity.builder()
        .selectionCount(((Number)row[1]).intValue())
        .route(route)
        .categoryOption((CategoryOptionEntity)row[0])
        .build())
    .toList();

reviewCategoryOptionTop3Repository.saveAll(top3Entities);

관련 링크

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions