This commit is contained in:
dahyeon committed 2026-04-27 19:23:26 -07:00
1 parent 1bbfc901e8
commit 4dba82ca03
18 files changed
+2146 -15

No files matched your search

+31 -12
View File
@@ -2,11 +2,16 @@
## Context
현재 상태:
현재 상태 (이미 가동 중인 인프라):
- 내전(Internal Match) 데이터는 `Match.result.games[]` 에 저장되고, 각 게임은 `Match.result.riotMatchIds[]` 를 통해 `RiotMatch.raw`(Match-V5 원본) 와 연결됨. (`Tournament-Result-수집-플랜.md` 의 결과 수집 워커가 이 자리를 채움)
- 그러나 사용자가 "어떤 내전들이 있었고, 우리 커뮤니티 안에서 누가 어떻게 했는지" 를 한눈에 볼 페이지가 없음.
- 또한 `apps/web/src/pages/UserHistoryPage.tsx` 의 큐 탭(소협/칼바람/우르프/아레나) 에서 **내전을 별도로 볼 수 없음**. 내전은 queueId=0 (custom) 이라 일반 큐 필터에 잡히지 않고 일반 솔로/자유랭크와 섞여 무의미함.
- 내전(Internal Match) 데이터가 `Match.result.games[]` 에 저장되고 있음. 결과 수집 워커가 `match-v5 by-puuid?type=tourney` 폴링으로 `info.tournamentCode` 매칭해 자동으로 채움.
- 각 게임은 `Match.result.riotMatchIds[]` 를 통해 `RiotMatch.raw` (Match-V5 원본) 와 연결됨 — raw 는 영구 저장.
- `MatchHistoryModule` 의 aggregation·캐시 패턴(Garnet) 도 이미 사용 중.
해결할 문제:
- 사용자가 "어떤 내전들이 있었고, 우리 커뮤니티 안에서 누가 어떻게 했는지" 를 한눈에 볼 페이지가 없음.
- `apps/web/src/pages/UserHistoryPage.tsx` 의 큐 탭(소협/칼바람/우르프/아레나) 에서 **내전을 별도로 볼 수 없음**. 내전은 queueId=0 (custom) 이라 일반 큐 필터에 잡히지 않고 일반 솔로/자유랭크와 섞여 무의미함.
추가하려는 것:
@@ -228,14 +233,16 @@ interface InternalMatchDetailResponse {
### 캐시 키 / TTL
```
riot:communitystats:matches:<cid>:<seasonId>:<from?>:<to?>:<cursor?> # 1h
riot:communitystats:leaderboard:<cid>:<seasonId>:<from?>:<to?> # 1h
riot:communitystats:teamInsights:<cid>:<seasonId>:<from?>:<to?> # 1h
riot:communitystats:matchDetail:<matchId> # 24h (불변)
riot:userInternalStats:<userId>:<cid>:<seasonId>:<from?>:<to?> # 1h
riot:communitystats:matches:<cid>:<seasonId>:<from?>:<to?>:<cursor?> # 1h
riot:communitystats:leaderboard:<cid>:<seasonId>:<from?>:<to?> # 1h
riot:communitystats:teamInsights:<cid>:<seasonId>:<from?>:<to?> # 1h
riot:communitystats:matchDetail:<matchId> # 24h (불변)
riot:userInternalStats:<userId>:<cid>:<seasonId>:<from?>:<to?> # 1h
```
매치가 새로 finished 될 때 invalidate: `community-stats.service` 가 `match.service` 의 finished 전환 직후 cache prefix delete (`riot:communitystats:*:<cid>:*`). Garnet `scanIterator + del`.
invalidate 트리거: 결과 수집 워커가 매치를 `finished` 로 전환할 때 `CommunityStatsCacheService.invalidate(cid)` 호출 → `riot:communitystats:*:<cid>:*` + `riot:userInternalStats:*:<cid>:*` prefix scan delete (Garnet `scanIterator + del`).
> `CommunityStatsCacheService.invalidate(cid)` 는 단일 헬퍼로 export — 외부에서 매치를 새로 만들거나 삭제하는 다른 흐름이 생기면 같은 헬퍼 한 줄 호출.
### 시즌 / 기간 필터
@@ -342,8 +349,8 @@ queryKey 컨벤션 따름: `['community-stats', 'matches', cid, seasonId, from,
- (수정) `apps/api/src/modules/global/database/schema.ts` — `Match` 인덱스 보강: `{ communityId: 1, status: 1, scheduledAt: -1 }` (커뮤니티 finished 매치 정렬)
- (수정) `apps/api/src/app.module.ts` — `CommunityStatsModule` import
- (신규) `apps/api/src/modules/community-stats/*` (위 5 파일)
- (수정) `apps/api/src/modules/match/match.service.ts` — finished 전환 직후 cache invalidate 호출
- (신규) `apps/api/src/modules/community-stats/*` (위 5 파일) — `CommunityStatsCacheService.invalidate(cid)` 헬퍼 export
- (수정) `apps/api/src/modules/match/match.service.ts` — finished 전환 직후 invalidate 호출
- (수정) `apps/api/src/modules/match-history/match-history.service.ts` — `getRecentMatches` 등에 `queueGroup === 'internal'` 분기, 데이터 소스를 `Match.result.games` 로 전환
### 프런트
@@ -411,6 +418,17 @@ queryKey 컨벤션 따름: `['community-stats', 'matches', cid, seasonId, from,
- 운영자용 export (CSV/JSON 다운로드)
- 페어 통계 sortable 표 — UI 형태 (한 유저 선택 → 다른 유저 페어 / 모든 페어 매트릭스)
## 사용 가능한 인프라 (이미 가동 중)
본 plan 은 이미 동작 중인 다음 모듈/필드를 그대로 활용합니다 — 추가 셋업 불필요:
| 모듈 / 필드 | 본 plan 에서의 역할 |
|---|---|
| `Match.result.games[]` (결과 수집 워커가 채움) | **데이터 소스 1차 공급원**. status=finished 매치만 통계 대상. |
| `RiotMatch.raw` (영구 저장) | LCK 통계용 raw 필드 (GPM/KP/데미지/시야/farm) lookup 소스. API 호출 0회. |
| `MatchHistoryModule` 의 aggregation·Garnet 캐시 패턴 | `community-stats.service` / `community-stats-cache.service` 가 동일 패턴 재사용. |
| `useDdragonManifest` (web) | 챔피언 이름·아이콘 풀이. |
## Verification
### 백엔드
@@ -447,4 +465,5 @@ queryKey 컨벤션 따름: `['community-stats', 'matches', cid, seasonId, from,
- aggregation 응답 시간 p95 < 500ms (100 매치 기준)
- Garnet 캐시 hit ratio > 70%
- 매치가 새로 finished 전환된 후 다음 통계 조회가 fresh aggregation (cache invalidate 정상 동작)
- 매치 finished 전환 후 invalidate 정상 동작 (캐시 키 scan 로그)