Skip to content

feat(family) : monthly api의 redis 실시간 처리 추가#286

Closed
pjh813 wants to merge 1 commit into
mainfrom
fix/336-family-jaehyeon
Closed

feat(family) : monthly api의 redis 실시간 처리 추가#286
pjh813 wants to merge 1 commit into
mainfrom
fix/336-family-jaehyeon

Conversation

@pjh813
Copy link
Copy Markdown
Contributor

@pjh813 pjh813 commented Mar 19, 2026

개요

monthly api의 redis 실시간 처리 추가

관련 BackLog

Resolves: (Backlog Number, ...)

PR 유형

  • 새로운 기능 추가
  • 버그 수정
  • CSS 등 사용자 UI 디자인 변경
  • 코드에 영향을 주지 않는 변경사항(오타 수정, 탭 사이즈 변경, 변수명 변경)
  • 코드 리팩토링
  • 주석 추가 및 수정
  • 문서 수정
  • 테스트 추가, 테스트 리팩토링
  • 빌드 부분 혹은 패키지 매니저 수정
  • 파일 혹은 폴더명 수정
  • 파일 혹은 폴더 삭제

PR Checklist

  • 커밋 메시지 컨벤션에 맞게 작성했습니다.
  • 변경 사항에 대한 테스트를 했습니다.(버그 수정/기능에 대한 테스트).

Summary by CodeRabbit

  • Improvements

    • Monthly shared pool usage calculation now leverages Redis caching for improved performance and accuracy, with automatic fallback to database values when unavailable.
  • Tests

    • Added unit tests for monthly shared usage tracking with caching scenarios.

@pjh813 pjh813 self-assigned this Mar 19, 2026
@github-actions
Copy link
Copy Markdown

정책 위반: main에는 dev에서만 PR이 가능합니다. 이 PR은 자동으로 닫습니다.

@github-actions github-actions Bot closed this Mar 19, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 19, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b2441629-5618-496d-8921-3c425e639959

📥 Commits

Reviewing files that changed from the base of the PR and between 89d249d and 51f78fb.

⛔ Files ignored due to path filters (2)
  • codex-logs/backend-stderr.log is excluded by !**/*.log
  • codex-logs/backend-stdout.log is excluded by !**/*.log
📒 Files selected for processing (5)
  • src/main/java/com/pooli/family/domain/dto/response/SharedPoolMonthlyUsageResDto.java
  • src/main/java/com/pooli/family/service/FamilySharedPoolsService.java
  • src/main/java/com/pooli/traffic/service/runtime/TrafficQuotaCacheService.java
  • src/main/resources/mapper/family/FamilySharedPoolMapper.xml
  • src/test/java/com/pooli/family/service/FamilySharedPoolsServiceTest.java

📝 Walkthrough

Walkthrough

This PR enhances family shared pool monthly usage reporting by introducing line-level tracking with lineId and integrating Redis cache reads. The service now computes maximum usage between database and Redis values, with graceful fallback when cache dependencies are unavailable.

Changes

Cohort / File(s) Summary
Data Model Enhancement
src/main/java/com/pooli/family/domain/dto/response/SharedPoolMonthlyUsageResDto.java
Added hidden lineId field to MemberUsageDto (annotated with @JsonIgnore and @Schema(hidden = true)) for internal line tracking without JSON/API exposure.
Service Logic Enhancement
src/main/java/com/pooli/family/service/FamilySharedPoolsService.java
Modified getFamilyMonthlySharedUsageTotal() to post-process results via new adjustMonthlySharedUsage() method. Reads monthly usage from Redis cache, normalizes negative DB values, and returns maximum of both sources. Falls back to 0L on missing Redis dependencies or exceptions.
Cache Service Extension
src/main/java/com/pooli/traffic/service/runtime/TrafficQuotaCacheService.java
Added public method readValueOrDefault(String key, long defaultValue) to safely read and parse Redis string values as long, with warning logging on parse failures.
Database Mapping Update
src/main/resources/mapper/family/FamilySharedPoolMapper.xml
Updated selectFamilyMonthlySharedUsageByLine to select l.line_id AS lineId and group by u.user_name, l.phone, and l.line_id for consistent aggregation.
Test Coverage
src/test/java/com/pooli/family/service/FamilySharedPoolsServiceTest.java
Added comprehensive unit tests with mocked Redis dependencies, covering scenarios where Redis provides higher usage values and fallback behavior when Redis providers are unavailable.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Service as FamilySharedPoolsService
    participant Mapper as MyBatis Mapper
    participant DB as Database
    participant KeyFactory as TrafficRedisKeyFactory
    participant Cache as TrafficQuotaCacheService
    participant Redis as Redis

    Client->>Service: getFamilyMonthlySharedUsageTotal()
    Service->>Mapper: selectFamilyMonthlySharedUsageByLine
    Mapper->>DB: SELECT monthlySharedPoolUsage, lineId
    DB-->>Mapper: Member usage records
    Mapper-->>Service: List<MemberUsageDto>
    
    loop For each member
        Service->>Service: adjustMonthlySharedUsage(dbUsage, lineId)
        Service->>Service: normalizeNonNegative(dbUsage)
        alt Redis available
            Service->>KeyFactory: Generate monthlySharedUsageKey(lineId, yearMonth)
            KeyFactory-->>Service: Redis key
            Service->>Cache: readValueOrDefault(key, 0L)
            Cache->>Redis: GET key
            Redis-->>Cache: value or null
            Cache-->>Service: Parsed long value
            Service->>Service: max(normalizedDbUsage, redisUsage)
        else Redis unavailable
            Service->>Service: Use normalizedDbUsage
        end
    end
    
    Service-->>Client: SharedPoolMonthlyUsageResDto with max values
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • [MERGE] Dev to Main #173: Modifies the same DTO, MyBatis mapper, and FamilySharedPoolsService during foundation of shared-pool usage API.
  • Dev #258: Implements similar Redis-based monthly shared usage logic with helper methods for normalization and cache reads.
  • Dev #226: Updates FamilySharedPoolsService and family mapper schema with lineId field additions and aggregation changes.

Suggested labels

feature

Suggested reviewers

  • Misu0616
  • hyeonRS

Poem

🐰 A line is tracked through Redis' gleaming store,
DB and cache now dance, each usage score,
The maximum wins when both compete,
But fallback's there when Redis can't compete! 🔄

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/336-family-jaehyeon
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can validate your CodeRabbit configuration file in your editor.

If your editor has YAML language server, you can enable auto-completion and validation by adding # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json at the top of your CodeRabbit configuration file.

@github-actions
Copy link
Copy Markdown

정책 위반: main에는 dev에서만 PR이 가능합니다. 이 PR은 자동으로 닫습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant