-
Notifications
You must be signed in to change notification settings - Fork 0
[25.07.26 / TASK-212] Feature - Leaderboard에 캐싱 추가 #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
""" Walkthrough
Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant LeaderboardService
participant Cache
participant Repository
Client->>LeaderboardService: getUserLeaderboard(sort, dateRange, limit)
LeaderboardService->>Cache: get(cacheKey)
alt Cache hit
Cache-->>LeaderboardService: cachedResult
LeaderboardService-->>Client: cachedResult
else Cache miss
Cache-->>LeaderboardService: null
LeaderboardService->>Repository: getUserLeaderboard(sort, dateRange, limit)
Repository-->>LeaderboardService: rawResult
LeaderboardService->>Cache: set(cacheKey, mappedResult, TTL)
LeaderboardService-->>Client: mappedResult
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15–20 minutes Possibly related PRs
Suggested reviewers
Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🧰 Additional context used🧠 Learnings (2)📓 Common learnings
src/services/__test__/leaderboard.service.test.ts (1)Learnt from: ooheunda 🔇 Additional comments (12)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (3)
src/services/leaderboard.service.ts (1)
31-31
: 캐시 저장 시 에러 처리 추가를 고려해주세요.현재 캐시 저장 실패 시 에러가 무시되어 전체 로직에 영향을 주지 않지만, 로깅을 통해 모니터링할 수 있도록 개선하는 것이 좋겠습니다.
- cache.set(cacheKey, result, LEADERBOARD_CACHE_TTL); + try { + await cache.set(cacheKey, result, LEADERBOARD_CACHE_TTL); + } catch (error) { + logger.warn('Failed to cache user leaderboard data', { cacheKey, error }); + }src/services/__test__/leaderboard.service.test.ts (2)
91-93
: 중복된 mock 클리어링을 제거해주세요.afterEach에서 이미 jest.clearAllMocks()를 호출하고 있으므로, beforeEach에서 중복으로 호출할 필요가 없습니다.
- beforeEach(() => { - jest.clearAllMocks(); - });
217-219
: 동일한 중복 mock 클리어링 제거 필요getUserLeaderboard 테스트와 마찬가지로 중복된 mock 클리어링을 제거해주세요.
- beforeEach(() => { - jest.clearAllMocks(); - });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/services/__test__/leaderboard.service.test.ts
(3 hunks)src/services/leaderboard.service.ts
(4 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: ooheunda
PR: Check-Data-Out/velog-dashboard-v2-api#27
File: src/services/leaderboard.service.ts:29-61
Timestamp: 2025-04-22T12:46:28.114Z
Learning: LeaderboardService의 mapRawResultToLeaderboardResponseData 메서드에서 `RawPostResult[] | RawUserResult[]` 타입을 사용하는 것이 `unknown[]`보다 타입 안전성 측면에서 더 좋은 접근 방식으로 판단됩니다.
src/services/leaderboard.service.ts (1)
Learnt from: ooheunda
PR: #27
File: src/services/leaderboard.service.ts:29-61
Timestamp: 2025-04-22T12:46:28.114Z
Learning: LeaderboardService의 mapRawResultToLeaderboardResponseData 메서드에서 RawPostResult[] | RawUserResult[]
타입을 사용하는 것이 unknown[]
보다 타입 안전성 측면에서 더 좋은 접근 방식으로 판단됩니다.
src/services/__test__/leaderboard.service.test.ts (1)
Learnt from: ooheunda
PR: #27
File: src/services/leaderboard.service.ts:29-61
Timestamp: 2025-04-22T12:46:28.114Z
Learning: LeaderboardService의 mapRawResultToLeaderboardResponseData 메서드에서 RawPostResult[] | RawUserResult[]
타입을 사용하는 것이 unknown[]
보다 타입 안전성 측면에서 더 좋은 접근 방식으로 판단됩니다.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: build-and-test (20)
- GitHub Check: build-and-test (23)
🔇 Additional comments (7)
src/services/leaderboard.service.ts (2)
1-1
: 캐시 설정 임포트가 올바르게 추가되었습니다.캐시 기능 구현을 위한 필수 의존성이 적절히 추가되었습니다.
11-11
: 캐시 TTL 상수 정의가 적절합니다.30분(1800초)의 캐시 만료 시간은 리더보드 데이터의 특성을 고려할 때 합리적인 설정입니다.
src/services/__test__/leaderboard.service.test.ts (5)
4-5
: 테스트 파일에 필요한 임포트가 올바르게 추가되었습니다.캐시 TTL 상수와 ICache 타입 임포트가 적절히 추가되어 테스트에서 캐시 기능을 검증할 수 있습니다.
8-13
: 캐시 모듈 모킹이 올바르게 구현되었습니다.jest.mock을 사용하여 캐시 모듈의 get, set 메서드를 적절히 모킹했습니다.
17-32
: 테스트 설정이 개선되었습니다.변수명이
repo
에서mockRepo
로 변경되어 가독성이 향상되었고, 캐시 모킹 설정도 적절히 추가되었습니다.
142-161
: 캐시 시나리오 테스트가 잘 구현되었습니다.캐시 히트와 미스 시나리오 모두 적절히 테스트되고 있으며, 캐시 키, TTL, 그리고 Repository 호출 여부를 정확히 검증하고 있습니다.
268-287
: 게시물 리더보드 캐시 테스트가 완전합니다.사용자 리더보드와 동일한 패턴으로 캐시 히트/미스 시나리오가 모두 테스트되어 일관성 있는 테스트 커버리지를 제공합니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
코드 잘 읽었습니다. 수고 많으셨습니다!
좋았던 점
- 네이밍을 확실히 해주신 점 (repo -> mockRepo, mockCache) 덕분에 읽기 편했습니다!
let mockPool: jest.Mocked<Pool>; | ||
let mockCache: jest.Mocked<ICache>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아주 조씀다~ 추상화 계층 mocking~~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이걸 노리고 딱 만들었는데 찰떡같이~ 리시브~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
좋았던 점
- 추상화 계층 mocking 과 이를 기반으로 캐시 여부에 따른 함수 호출 여부까지, 빠짐 없는 유닛테스트 너무 잘봤습니다!!
아쉬운 점
- 혹시 캐시 get / set 과정에 시리얼라이징 이슈는 없으셨어요? 원하는 객체 형태로 바로 잘 나오던가요?
@Nuung |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
코드 잘 읽었습니다. 고생하셨습니다~!!
좋았던 점
- 캐시 로직 구조가 명확해서 좋았습니다! 특히 TTL도 상수로 따로 분리된 점이 좋은 것 같아요!👍
- 캐시 hit/miss에 대한 테스트코드를 꼼꼼히 작성해주신 부분도 좋았습니다!
- mock 객체의 역할이 명확하게 드러나도록 mockRepo, mockCache로 네이밍 해주신 부분 좋은 것 같습니다!
🔥 변경 사항
🏷 관련 이슈
📸 스크린샷 (UI 변경 시 필수)
X
📌 체크리스트
Summary by CodeRabbit
신규 기능
테스트