Skip to content

[FIX#107] AssetBalanceService 조회 로직 수정#108

Merged
seamooll merged 2 commits intomainfrom
fix/#107-goal-balance
Feb 12, 2026
Merged

[FIX#107] AssetBalanceService 조회 로직 수정#108
seamooll merged 2 commits intomainfrom
fix/#107-goal-balance

Conversation

@dohy-eon
Copy link
Member

🔗 Related Issue

📝 Summary

동기화 작업 시 발생하는 DB 중복 조회를 방지하고 실시간으로 파싱된 잔액 데이터를 즉시 반환하도록 개선

🔄 Changes

  • API 변경 (추가/수정)
    • AssetResDTO.AssetSyncResult에 실시간 계좌 잔액 정보를 담는 latestBalances 필드 추가
  • 데이터 및 도메인 변경 (DB, 비즈니스 로직)
    • AssetFetchService: API 수집 데이터에서 계좌별 최신 잔액을 추출하여 DB 조회 없이 DTO로 전달하는 로직 구현
    • AssetBalanceService: 동기화 결과에 잔액 정보가 포함된 경우 bankTransactionRepository 조회를 생략하고 즉시 반환하도록 수정
  • 설정 또는 인프라 관련 변경
  • 리팩토링
    • AssetSyncProcessor: 비동기 동기화 프로세스 내에서 AssetFetchService의 변경된 반환 타입을 적용

💬 Questions & Review Points

레이스 컨디션 방지: 동기화 직후 DB 반영 지연으로 인해 이전 잔액이 조회되는 문제를 방지하기 위해 메모리 내 데이터를 우선 사용하도록 했습니다. 이 접근 방식이 서비스의 다른 도메인과 일관성이 있는지, 그냥 사용해도 괜찮은지 체크 부탁드립니다.

예외 처리: AssetBalanceService에서 동기화 실패 시 fallback으로 기존 db값 사용하게 처리했는데 코드가 적절한지 체크 부탁드리겠습니다.

API 테스트는 따로 진행하지 않았습니다.

✅ Checklist

  • API 테스트 완료
  • 테스트 결과 사진 첨부
  • 빌드 성공 확인 (./gradlew build)

@dohy-eon dohy-eon requested a review from seamooll February 11, 2026 20:36
@dohy-eon dohy-eon self-assigned this Feb 11, 2026
@dohy-eon dohy-eon added the 🛠️ fix 버그 수정 label Feb 11, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello @dohy-eon, 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은 자산 동기화 과정에서 발생하는 비효율성을 개선하고, 사용자에게 보다 신속하고 정확한 최신 잔액 정보를 제공하는 것을 목표로 합니다. 동기화 직후 발생할 수 있는 데이터 불일치(레이스 컨디션)를 방지하기 위해, API로부터 수집된 실시간 잔액 데이터를 우선적으로 활용하도록 로직을 변경하여 DB 조회 부하를 줄이고 응답성을 향상시켰습니다.

Highlights

  • DB 중복 조회 방지: 자산 동기화 시 발생하는 DB 중복 조회를 방지하고 실시간으로 파싱된 잔액 데이터를 즉시 반환하도록 로직을 개선했습니다.
  • AssetResDTO.AssetSyncResult 업데이트: API 응답으로 직접 사용되지 않는 내부 DTO인 AssetSyncResult에 계좌 ID별 최신 잔액 정보를 담는 latestBalances 필드와 관련 헬퍼 메서드를 추가했습니다.
  • AssetFetchService 로직 변경: AssetFetchService에서 API 수집 데이터로부터 계좌별 최신 잔액을 추출하여 DB 조회 없이 DTO로 전달하는 로직을 구현했습니다.
  • AssetBalanceService 최적화: AssetBalanceService는 동기화 결과에 잔액 정보가 포함된 경우 bankTransactionRepository 조회를 생략하고 즉시 반환하도록 수정되었습니다.
  • AssetSyncProcessor 리팩토링: AssetSyncProcessor는 비동기 동기화 프로세스 내에서 AssetFetchService의 변경된 반환 타입을 적용하도록 리팩토링되었습니다.

🧠 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.

Changelog
  • src/main/java/org/umc/valuedi/domain/asset/dto/res/AssetResDTO.java
    • AssetSyncResult 클래스에 NoArgsConstructor를 추가했습니다.
    • 계좌 ID별 최신 잔액을 저장하는 latestBalances 맵 필드와 관련 헬퍼 메서드(hasLatestBalanceFor, getLatestBalanceFor, addLatestBalance)를 추가했습니다.
  • src/main/java/org/umc/valuedi/domain/asset/service/AssetBalanceService.java
    • syncAndGetLatestBalance 메서드에서 AssetFetchService의 동기화 결과(AssetSyncResult)에 실시간 잔액 정보가 포함되어 있을 경우, 해당 정보를 즉시 반환하도록 로직을 수정하여 DB 조회를 최적화했습니다.
    • 동기화 실패 시 기존 DB 잔액을 사용하는 로직의 로그 메시지를 상세화했습니다.
    • 불필요한 주석을 제거했습니다.
  • src/main/java/org/umc/valuedi/domain/asset/service/command/AssetFetchService.java
    • fetchAndSaveLatestData 메서드 내에서 realTimeBalances 맵을 초기화하고, 수집된 모든 거래내역 중 계좌별 가장 최신 잔액을 추출하여 이 맵에 저장하도록 로직을 추가했습니다.
    • AssetResDTO.AssetSyncResult 빌더에 realTimeBalances를 전달하도록 수정했습니다.
    • Collectors.toList() 호출을 toList()로 변경하여 코드 스타일을 개선했습니다.
    • 불필요한 주석을 제거했습니다.
Activity
  • 동기화 직후 DB 반영 지연으로 인한 레이스 컨디션 방지를 위해 메모리 내 데이터를 우선 사용하는 접근 방식의 일관성 및 적절성에 대한 검토를 요청했습니다.
  • AssetBalanceService에서 동기화 실패 시 fallback으로 기존 DB 값을 사용하는 예외 처리 코드의 적절성에 대한 검토를 요청했습니다.
  • API 테스트는 아직 진행되지 않았습니다.
  • 빌드는 성공적으로 완료되었습니다.
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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

Copy link

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

Choose a reason for hiding this comment

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

Code Review

This Pull Request enhances the asset synchronization logic by preventing redundant DB queries and immediately returning real-time parsed balance data, improving user experience and reducing race conditions. It introduces a latestBalances field in AssetResDTO.AssetSyncResult and streamlines data flow from AssetFetchService to AssetBalanceService. However, a security audit revealed two significant concerns: a potential Insecure Direct Object Reference (IDOR) vulnerability due to inadequate ownership verification for the memberId parameter, and the logging of sensitive financial information (account balances) in application logs. Addressing these security issues is essential to safeguard user data and maintain proper access controls.

* 동기화 실패 시 기존 잔액을 반환합니다.
*/
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public Long syncAndGetLatestBalance(Long memberId, Long accountId) {

Choose a reason for hiding this comment

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

security-high high

The method syncAndGetLatestBalance accepts memberId and accountId as parameters and uses them to fetch and return sensitive financial data (account balance). While it verifies that the accountId belongs to the memberId (line 50), it does not verify that the memberId belongs to the currently authenticated user. An attacker could potentially guess or discover another user's memberId and accountId to retrieve their real-time account balance. It is recommended to verify that the memberId matches the ID of the authenticated user, or retrieve the authenticated user's ID directly from the security context.

@seamooll seamooll merged commit a1752e7 into main Feb 12, 2026
1 check passed
@seamooll seamooll deleted the fix/#107-goal-balance branch February 12, 2026 03:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🛠️ fix 버그 수정

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FIX] 배포 환경에서 목표 생성 시 최신 잔액 조회 지연 현상 개선

2 participants