Skip to content

[DABOM-514] recap-job 성능 개선 - #29

Merged
k0081915 merged 8 commits into
developfrom
refactor/DABOM-514
Mar 19, 2026
Merged

k0081915 merged 8 commits into
developfrom
refactor/DABOM-514

Conversation

@k0081915

@k0081915 k0081915 commented Mar 19, 2026

Copy link
Copy Markdown
Member

🍀 이슈 & 티켓 넘버


🎯 목적

weekly-family-recap-jobmonthly-family-recap-job의 병목은 familyId 1건마다 집계 SQL을 반복 호출하는 구조였다.
이번 변경은 batch-core 기준으로 리캡 집계를 chunk 단위 벌크 조회로 전환해, 운영 데이터 스케일에서 배치 처리 시간을 줄이기 위한 목적이다.

📝 변경 사항

  • weekly-family-recap-job
    • WeeklyFamilyRecapAggregationRepositoryaggregate(List<Long>, weekStartDate) 벌크 집계 추가
    • step에서 processor 단건 처리 대신 writer가 chunk 전체 familyIds를 받아 벌크 집계 후 batch upsert 하도록 변경
    • WeeklyFamilyRecapProcessor는 기존 단건 process()를 유지하면서 processAll() 벌크 조립 메서드 추가
  • monthly-family-recap-job
    • MonthlyFamilyRecapAggregationRepositoryfamilyIds 기준 벌크 집계 구조로 리팩터링
    • full weekly snapshot, partial raw usage/mission/appeal, carry-in, appeal highlights를 chunk 단위로 한 번에 조회하도록 변경
    • MonthlyFamilyRecapProcessorprocessAll() 벌크 조립 메서드 추가
    • writer가 chunk 전체를 받아 벌크 집계 후 batch upsert 하도록 변경
  • 배치 설정 조정
    • batch.yml에서 weekly/monthly recap의 chunk-size, db-fetch-size 기본값 상향
  • 테스트 갱신
    • writer 테스트를 chunk familyIds 입력 구조에 맞게 수정
    • repository 테스트에 벌크 집계 경로 검증 추가

📂 변경 범위

Job api (controller/service/dto) job config step config reader processor writer global (config/launcher/listener)
weekly-family-recap / monthly-family-recap [x] [x] [x] [x]

🖥️ 주요 코드 설명

@Override
public void write(Chunk<? extends Long> chunk) {
    if (chunk.isEmpty()) {
        return;
    }

    List<MonthlyFamilyRecapRow> rows = processor.processAll(List.copyOf(chunk.getItems()));
    SqlParameterSource[] batchParams =
            rows.stream().map(this::toSqlParameterSource).toArray(SqlParameterSource[]::new);

    jdbcTemplate.batchUpdate(UPSERT_MONTHLY_RECAP_SQL, batchParams);
}

기존에는 familyId 1건마다 processor -> repository.aggregate(familyId, ...) 구조로 반복 집계했다.
변경 후에는 writer가 chunk 전체 familyIds를 받아 processAll()로 벌크 집계 결과를 조립하고, upsert만 한 번에 수행한다.

💬 리뷰어에게

  • writer가 chunk 단위 집계 조립까지 담당하게 되면서 책임 경계가 기존보다 두꺼워졌습니다. 리캡 배치 성능 개선을 우선한 구조 변경이라, 이 부분을 특히 봐주시면 됩니다.
  • 월간 리캡의 appeal highlights는 per-family 쿼리 반복 대신 월간 승인 appeal 원본을 한 번에 읽어 메모리에서 가족별로 조립하도록 바꿨습니다.

📋 체크리스트

기본

  • Merge 대상 브랜치가 올바른가?
  • ./gradlew build가 정상적으로 통과하는가?
  • Spotless / Checkstyle을 통과하는가? (./gradlew spotlessApply checkstyleMain)
  • 전체 변경사항이 500줄을 넘지 않는가?

배치 코드 품질

  • 의존성 방향을 준수하는가? (Controller → Service → BatchJobLauncher → Job → Step → Reader/Processor/Writer)
  • 모든 Job에 JobResultListener를 등록했는가?
  • Reader/Processor/Writer가 각각 단일 책임만 수행하는가?
  • Job/Step 이름이 kebab-case인가?
  • 하나의 Config 파일에 하나의 Job/Step만 정의했는가?

테스트

  • 신규 배치 로직에 대한 단위 테스트를 작성했는가?

📌 참고 사항

@k0081915 k0081915 self-assigned this Mar 19, 2026
@github-actions
github-actions Bot requested a review from swthewhite March 19, 2026 10:11
@github-actions github-actions Bot added size/XL PR size: XL refactor 리팩토링 style 코드 스타일 변경 test 테스트 코드 labels Mar 19, 2026
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

이 PR은 weekly-family-recap-jobmonthly-family-recap-job의 성능을 대폭 개선하는 것을 목표로 합니다. 기존에는 familyId별로 개별적인 데이터베이스 쿼리를 수행하여 비효율적이었던 집계 방식을, 이제는 청크 단위로 여러 familyId를 한 번에 처리하는 벌크 방식으로 전환했습니다. 이를 통해 운영 환경에서 배치 작업의 처리 시간을 단축하고 전반적인 시스템 효율성을 향상시켰습니다.

Highlights

  • 벌크 집계 로직 도입: weekly-family-recap-jobmonthly-family-recap-job에 청크 단위 벌크 집계 로직이 추가되었습니다. 기존의 familyId 1건당 반복적인 SQL 호출 방식에서 벗어나 성능을 개선했습니다.
  • Writer 역할 변경 및 Processor 통합: 스텝의 processor가 단건 처리를 담당하는 대신, writer가 청크 전체 familyIds를 받아 벌크 집계 후 배치 업서트하도록 변경되었습니다. WeeklyFamilyRecapProcessorMonthlyFamilyRecapProcessor에는 processAll() 벌크 조립 메서드가 추가되었습니다.
  • Aggregation Repository 리팩토링: MonthlyFamilyRecapAggregationRepositoryfamilyIds 기준 벌크 집계 구조로 리팩토링되었습니다. 전체 주간 스냅샷, 부분 원본 사용량/미션/이의제기, 이월 데이터, 이의제기 하이라이트 등을 청크 단위로 한 번에 조회하도록 변경되었습니다.
  • 배치 설정 조정: batch.yml에서 weekly/monthly recap 작업의 chunk-sizedb-fetch-size 기본값이 상향 조정되어 배치 처리 효율이 증대되었습니다.
  • 테스트 갱신: writer 테스트가 청크 familyIds 입력 구조에 맞게 수정되었으며, repository 테스트에 벌크 집계 경로 검증 로직이 추가되었습니다.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions

This comment was marked as resolved.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

이번 PR은 recap-job의 성능 개선을 위해 기존의 건별 집계 방식에서 chunk 단위 벌크 조회 및 처리 방식으로 리팩터링하는 중요한 변경을 담고 있습니다. 전반적으로 변경의 목적에 맞게 코드가 잘 수정되었으며, 특히 Writer에서 Processor를 호출하여 벌크 처리를 수행하는 구조 변경은 성능 향상을 위한 합리적인 트레이드오프로 보입니다. MonthlyFamilyRecapAggregationRepository의 리팩터링은 복잡하지만, Mutable 내부 클래스를 활용하여 상태를 관리하고 최종 결과를 조립하는 방식은 가독성과 유지보수성을 높이는 좋은 패턴입니다. 코드 중복을 줄여 유지보수성을 더욱 향상시킬 수 있는 부분에 대해 한 가지 의견을 남겼습니다. 좋은 변경 감사합니다.

@github-actions github-actions Bot added the fix 버그 수정 label Mar 19, 2026
@github-actions

This comment was marked as resolved.

@github-actions

This comment was marked as duplicate.

@github-actions

Copy link
Copy Markdown

SonarQube Quality Summary (Community)

Quality Gate PASSED

Branch: refactor/DABOM-514
Compared to: default branch

Issues

  • 🐞 Bugs: 9
  • 🔐 Vulnerabilities: 0
  • 📎 Code Smells: 91

Measures

  • Coverage: 0%
  • Duplication: 0%

🔗 Dashboard: https://sonarqube.swthewhite.store/dashboard?id=dabom-batch-core&branch=refactor/DABOM-514

Generated automatically by GitHub Actions.

@ChoiSeungeon ChoiSeungeon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확인했습니다.

@k0081915
k0081915 merged commit 7f57378 into develop Mar 19, 2026
12 of 13 checks passed
@k0081915
k0081915 deleted the refactor/DABOM-514 branch March 19, 2026 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix 버그 수정 refactor 리팩토링 size/XL PR size: XL style 코드 스타일 변경 test 테스트 코드

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DABOM-514] recap-job 성능 개선

2 participants