-
Notifications
You must be signed in to change notification settings - Fork 1
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
[FEATURE] Attaching caching #118
Conversation
📝 Walkthrough📝 WalkthroughWalkthrough이 변경 사항은 Changes
Assessment against linked issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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: 5
🧹 Outside diff range and nitpick comments (4)
src/tag/tag.controller.ts (1)
Line range hint
45-54
: 엔드포인트별 세분화된 캐시 전략이 필요합니다.현재 구현의 개선 필요 사항:
findAll
메서드:
- 쿼리 파라미터에 따라 다른 캐시 전략 적용 필요
- 검색 결과에 대한 별도의 캐시 TTL 설정 고려
create
메서드:
- 태그 생성 후 관련된 캐시 데이터 무효화 로직 추가 필요
다음과 같은 구현을 제안드립니다:
@Get() + @CacheKey('tags') + @CacheTTL(3600) async findAll(@Query() query: GetTagDto): Promise<TagResDto | TagResDto[]> { if (query.name) { + const cacheKey = `tag:${query.name}`; return this.tagService.findTag({ name: query.name }); } if (query.search) { + const cacheKey = `search:${query.search}`; + @CacheTTL(1800) return this.tagService.searchTags({ search: query.search }); } return this.tagService.findAllTags(); } @Post() + @CacheEvict('tags') async create(@Body() body: CreateTagDto) { return this.tagService.createTag(body); }Also applies to: 63-71
src/notice/notice.controller.ts (2)
47-47
: 캐시 전략 검토가 필요합니다.클래스 수준에서
CacheInterceptor
를 적용하면 모든 엔드포인트에 캐싱이 적용됩니다. 다음 사항들을 고려해야 합니다:
- POST/PATCH/DELETE 요청에 대한 캐시 무효화 전략
- 사용자별 응답이 다른 엔드포인트의 캐시 키 전략
- 인증 상태에 따른 캐시 응답 처리
다음과 같은 개선을 제안드립니다:
- GET 메소드에만 선택적으로 캐시를 적용
- 사용자별 캐시 키 전략 구현
- 캐시 무효화 로직 추가
예시 구현이 필요하시다면 말씀해 주세요.
캐시 키 전략 구현이 필요합니다
@nestjs/cache-manager
의CacheInterceptor
가 적용되어 있지만, 사용자 UUID와 쿼리 파라미터에 따라 다른 결과를 반환하는getNoticeList
메소드에 대한 적절한 캐시 키 전략이 구현되어 있지 않습니다. 다음 작업이 필요합니다:
CacheKey
데코레이터나 커스텀 캐시 키 생성 로직을 구현하여 다음 요소들을 캐시 키에 포함:
- 사용자 UUID (
user?.uuid
)- 쿼리 파라미터 (
GetAllNoticeQueryDto
)🔗 Analysis chain
Line range hint
62-71
: getNoticeList 메소드의 캐시 키 전략이 필요합니다.이 엔드포인트는 사용자 정보(
user?.uuid
)와 쿼리 파라미터에 따라 다른 결과를 반환합니다. 캐시 키에 이러한 요소들을 포함시켜야 합니다.캐시 키 생성 로직을 확인하기 위해 다음 스크립트를 실행합니다:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check if cache key generation logic exists # Test: Search for cache key customization in the codebase rg "CacheKey|createKey|cacheKey"Length of output: 34
Script:
#!/bin/bash # Check for cache-related decorators and implementations rg -i "cache" --type typescript -A 5 # Check for any cache configuration or setup fd -e ts -e js cache # Look for cache-related imports and usage ast-grep --pattern 'import { $_ } from $_' | rg -i "cache"Length of output: 153
Script:
#!/bin/bash # Search for cache-related code rg -t ts -t js -i "cache" # Look for cache module imports rg -t ts -t js "@.*Cache" # Check notice service implementation fd -e ts "notice.service"Length of output: 1703
Script:
#!/bin/bash # Check notice service implementation for cache key customization cat src/notice/notice.service.ts # Look for cache key customization in the controller cat src/notice/notice.controller.ts # Check for any cache key decorator usage rg -t ts "CacheKey|@Cache"Length of output: 17262
src/tag/tag.module.ts (1)
26-26
: TTL 값 검토 필요현재 TTL 값을
3 * 60
으로 설정하여 180초로 설정하셨습니다. 이 값이 비즈니스 요구사항에 부합하는지 확인해주세요.애플리케이션의 캐싱 전략에 따라 TTL 값을 조정하실 수 있습니다.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (1)
package-lock.json
is excluded by!**/package-lock.json
📒 Files selected for processing (7)
package.json
(3 hunks)src/crawl/crawl.controller.ts
(2 hunks)src/crawl/crawl.module.ts
(2 hunks)src/notice/notice.controller.ts
(2 hunks)src/notice/notice.module.ts
(3 hunks)src/tag/tag.controller.ts
(2 hunks)src/tag/tag.module.ts
(1 hunks)
🔇 Additional comments (10)
src/crawl/crawl.module.ts (2)
5-5
: 필요한 모듈들이 올바르게 임포트되었습니다.
캐시 기능 구현에 필요한 모든 의존성이 적절하게 추가되었습니다.
Also applies to: 11-12
26-31
: Redis 구성이 일관되게 적용되었는지 확인이 필요합니다.
다른 모듈에서도 동일한 Redis 구성을 사용하는지 확인이 필요합니다.
✅ Verification successful
Redis 구성이 일관되게 적용되어 있음을 확인했습니다.
모든 모듈(tag, notice, crawl)에서 동일한 Redis 구성을 사용하고 있습니다:
- Redis 호스트와 포트가 환경 변수에서 일관되게 가져와짐 (
REDIS_HOST
,REDIS_PORT
) - TTL 값이 모든 모듈에서 동일하게 3분(3 * 60)으로 설정됨
- Redis 스토어 설정 패턴이 일관됨
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Redis 구성 일관성 검사
# 환경 설정 파일에서 Redis 관련 설정 확인
echo "Redis 환경 설정 확인:"
rg -l "REDIS_(HOST|PORT|TTL)" .env*
# 다른 모듈의 Redis 구성 검사
echo "\nRedis 스토어 구성 패턴 검사:"
rg -A 5 "redisStore\({" --type typescript
Length of output: 313
Script:
#!/bin/bash
# Redis 설정 검색 - 수정된 스크립트
echo "Redis 환경 설정 검색:"
rg "REDIS_" -l
echo "\nRedis 스토어 사용 패턴 검색:"
rg "redisStore" -A 5 --type typescript
echo "\nRedis 관련 설정 및 임포트 검색:"
rg "redis" -i --type typescript -A 3
Length of output: 405
Script:
#!/bin/bash
# Redis 설정 상세 검색
echo "Redis 설정이 있는 파일들의 내용 확인:"
for file in src/tag/tag.module.ts src/notice/notice.module.ts src/app.module.ts src/crawl/crawl.module.ts; do
echo "\n=== $file 파일 내용 ==="
cat "$file" | grep -A 5 -B 2 "REDIS_"
done
echo "\nRedis 스토어 설정 검색:"
for file in src/tag/tag.module.ts src/notice/notice.module.ts src/app.module.ts src/crawl/crawl.module.ts; do
echo "\n=== $file 파일 내용 ==="
cat "$file" | grep -A 5 -B 2 "redisStore"
done
Length of output: 4800
src/notice/notice.module.ts (1)
6-6
: 필요한 모듈들이 올바르게 임포트되었습니다.
캐시 기능 구현에 필요한 모든 의존성이 적절하게 포함되어 있습니다.
Also applies to: 15-16
src/crawl/crawl.controller.ts (2)
8-8
: 캐시 관련 임포트가 올바르게 추가되었습니다!
필요한 캐시 인터셉터 관련 임포트들이 적절하게 추가되었습니다.
Also applies to: 24-24
24-24
: 캐시 모듈 설정을 확인해주세요.
Redis 캐시 설정이 올바르게 구성되어 있는지 확인이 필요합니다.
다음 스크립트를 실행하여 설정을 확인하세요:
✅ Verification successful
Redis 캐시 설정이 올바르게 구성되어 있습니다.
crawl.module.ts에서 CacheModule이 다음과 같이 적절하게 구성되어 있음을 확인했습니다:
- Redis 호스트와 포트를 ConfigService를 통해 환경 변수에서 가져옴
- TTL이 3분으로 설정됨
- redisStore를 사용하여 Redis 연결 구성
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Redis 캐시 설정 확인
# 캐시 모듈 설정 확인
echo "캐시 모듈 설정 확인 중..."
rg "CacheModule.register" -A 10
# 환경 설정 파일에서 Redis 설정 확인
echo "Redis 환경 설정 확인 중..."
fd -e env -e yaml -e json -x cat {} | rg -i "redis"
Length of output: 4412
src/tag/tag.controller.ts (1)
8-8
: LGTM - 필요한 임포트가 올바르게 추가되었습니다.
캐시 기능 구현을 위한 필수 임포트들이 적절하게 추가되었습니다.
Also applies to: 26-26
package.json (1)
27-27
:
캐시 관련 패키지 버전 호환성 및 보안 고려사항
- 버전 호환성 문제:
@nestjs/[email protected]
는 NestJS v10과 호환성 문제가 있을 수 있습니다. 최신 버전인^3.0.0
으로 업그레이드하는 것을 권장합니다.[email protected]
는 더 이상 유지보수되지 않는 버전입니다. 대신@socket.io/redis-adapter
또는@redis/client
를 사용하는 것을 고려해보세요.
- Redis 보안 설정:
- Redis를 캐시 저장소로 사용할 때는 프로덕션 환경에서 적절한 보안 설정이 필요합니다.
- 환경 변수를 통해 Redis 연결 설정을 관리하고 있는지 확인해주세요.
Redis 설정 관련 코드를 확인하기 위해 다음 스크립트를 실행합니다:
Also applies to: 36-36
✅ Verification successful
Redis 구성이 적절하게 구현되어 있으나 패키지 버전 업데이트가 필요합니다
- Redis 보안 설정이 적절히 구현되어 있습니다:
- 환경 변수(
REDIS_HOST
,REDIS_PORT
)를 통한 설정 관리 - ConfigService를 통한 필수 값 검증 (
getOrThrow
사용) - TTL이 3분으로 적절하게 설정됨
- 다음 버전 업데이트를 권장드립니다:
@nestjs/cache-manager
를 v3.0.0 이상으로 업그레이드cache-manager-redis-store
를 최신 대체 패키지로 마이그레이션
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify Redis configuration and environment variables
# Test: Search for Redis configuration in the codebase
rg -l 'redis' --type ts
# Test: Check for environment variable usage in configuration
rg -l 'ConfigService.*redis' --type ts
Length of output: 158
Script:
#!/bin/bash
# Check Redis configuration implementation in the found modules
echo "=== Redis Configuration in notice.module.ts ==="
cat src/notice/notice.module.ts
echo -e "\n=== Redis Configuration in tag.module.ts ==="
cat src/tag/tag.module.ts
echo -e "\n=== Redis Configuration in app.module.ts ==="
cat src/app.module.ts
echo -e "\n=== Redis Configuration in crawl.module.ts ==="
cat src/crawl/crawl.module.ts
# Search for cache module configuration
echo -e "\n=== Cache Module Configuration ==="
rg "CacheModule" -A 5 --type ts
# Check for environment variables related to Redis
echo -e "\n=== Environment Variables Configuration ==="
fd -t f "env" -X cat {}
Length of output: 8419
src/notice/notice.controller.ts (1)
13-13
: 임포트 변경사항이 적절합니다.
캐시 인터셉터 관련 임포트가 올바르게 추가되었습니다.
Also applies to: 41-41
src/tag/tag.module.ts (2)
8-10
: 캐시 모듈 및 설정 관련 import가 정확합니다
CacheModule
, CacheStore
, ConfigModule
, ConfigService
, redisStore
의 import가 정확히 추가되었습니다.
23-24
: 포트 번호 형변환이 필요합니다
configService.getOrThrow<number>('REDIS_PORT')
로 포트 번호를 가져오고 있는데, 환경 변수는 기본적으로 문자열로 반환되므로 숫자로 명시적으로 변환해야 합니다.
port: parseInt(configService.getOrThrow<string>('REDIS_PORT'), 10)
으로 수정하여 포트 번호를 정확히 숫자로 변환하는 것을 권장합니다.
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
🧹 Outside diff range and nitpick comments (1)
libs/redis-cache/src/redis-cache.module.ts (1)
6-27
: 아키텍처 관련 제안사항Redis 캐시의 안정성을 높이기 위해 다음 기능들의 추가를 고려해보세요:
- 헬스체크 메커니즘
- 재연결 정책
- 서킷브레이커 패턴
이러한 기능들은 프로덕션 환경에서의 안정성을 크게 향상시킬 수 있습니다.
이러한 기능들의 구현을 위한 코드를 생성해드릴까요?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (10)
libs/redis-cache/src/index.ts
(1 hunks)libs/redis-cache/src/redis-cache.module.ts
(1 hunks)libs/redis-cache/tsconfig.lib.json
(1 hunks)nest-cli.json
(1 hunks)package.json
(3 hunks)src/crawl/crawl.module.ts
(2 hunks)src/notice/notice.module.ts
(2 hunks)src/tag/tag.module.ts
(1 hunks)test/jest-e2e.json
(1 hunks)tsconfig.json
(1 hunks)
✅ Files skipped from review due to trivial changes (2)
- libs/redis-cache/src/index.ts
- libs/redis-cache/tsconfig.lib.json
🚧 Files skipped from review as they are similar to previous changes (4)
- package.json
- src/crawl/crawl.module.ts
- src/notice/notice.module.ts
- src/tag/tag.module.ts
🔇 Additional comments (7)
test/jest-e2e.json (2)
19-19
: 코드 포맷팅이 올바르게 적용되었습니다.
후속 매핑을 위한 콤마 추가가 적절히 이루어졌습니다.
20-21
: Redis 캐시 모듈 매핑이 적절히 구성되었습니다.
모듈 매핑이 다른 라이브러리들과 일관된 패턴을 따르고 있습니다. 하지만 실제 모듈 구조가 올바르게 설정되어 있는지 확인이 필요합니다.
다음 스크립트를 실행하여 Redis 캐시 모듈 구조를 확인하겠습니다:
✅ Verification successful
Redis 캐시 모듈 매핑이 정확하게 구성되었음을 확인했습니다.
- Redis 캐시 모듈이
libs/redis-cache/src/
경로에 올바르게 구현되어 있습니다. - 모듈 구조가 표준을 따르고 있으며,
index.ts
와redis-cache.module.ts
파일이 예상대로 존재합니다. tag
,notice
,crawl
모듈에서@lib/redis-cache
를 올바르게 참조하고 있습니다.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Redis 캐시 모듈 구조 확인
# libs/redis-cache 디렉토리 존재 여부 확인
echo "Redis 캐시 모듈 디렉토리 구조 확인:"
fd --type d "redis-cache" libs/
# 소스 파일 존재 여부 확인
echo -e "\nRedis 캐시 모듈 소스 파일 확인:"
fd --type f . libs/redis-cache/src/
Length of output: 276
Script:
#!/bin/bash
# Redis 캐시 모듈의 내용과 구조를 더 자세히 확인
# index.ts 파일 내용 확인
echo "index.ts 파일 내용:"
cat libs/redis-cache/src/index.ts
echo -e "\nredis-cache.module.ts 파일 내용:"
cat libs/redis-cache/src/redis-cache.module.ts
# 모듈 의존성 확인
echo -e "\n모듈 의존성 확인:"
rg "@lib/redis-cache" --type ts -l
Length of output: 1202
libs/redis-cache/src/redis-cache.module.ts (1)
1-5
: 의존성 선언이 적절합니다!
필요한 모든 모듈과 타입이 올바르게 임포트되었습니다.
tsconfig.json (2)
39-44
: 모듈 경로가 일관성 있게 구성되었습니다.
새로 추가된 Redis 캐시 라이브러리의 경로 매핑이 기존의 다른 라이브러리들(@lib/prisma, @lib/infoteam-idp, @lib/logger)과 동일한 패턴을 따르고 있어 일관성이 잘 유지되었습니다.
39-44
: 경로 매핑 추가 확인이 필요합니다.
Redis 캐시 라이브러리에 대한 경로 매핑이 올바르게 추가되었습니다. 다만, 해당 디렉토리가 실제로 존재하는지 확인이 필요합니다.
✅ Verification successful
Let me verify if the directory structure matches the path mappings by checking the src directory.
경로 매핑이 정확히 설정되었습니다
디렉토리 구조 검증 결과, libs/redis-cache/src/
경로가 존재하며 tsconfig.json의 경로 매핑과 정확히 일치합니다. 설정이 올바르게 되어있어 추가 수정이 필요하지 않습니다.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the existence of the Redis cache library directory
# Test: Check if the Redis cache library directory exists
fd -t d "redis-cache" libs/
Length of output: 45
Script:
#!/bin/bash
# Check if the src directory exists within redis-cache and list its contents
fd -t d "src" libs/redis-cache/
Length of output: 53
nest-cli.json (2)
37-44
: 설정이 올바르게 구성되었습니다!
NestJS 라이브러리 구조에 맞게 redis-cache 모듈이 잘 구성되어 있습니다.
37-44
: 참조된 파일들의 존재 여부를 확인해주세요.
redis-cache 라이브러리의 필수 파일들이 모두 존재하는지 확인이 필요합니다.
✅ Verification successful
필수 파일들이 모두 존재하는 것을 확인했습니다.
redis-cache 라이브러리의 모든 필수 파일들이 정상적으로 존재합니다:
libs/redis-cache/src/index.ts
(엔트리 파일)libs/redis-cache/tsconfig.lib.json
(TypeScript 설정)libs/redis-cache/src/redis-cache.module.ts
(모듈 파일)
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the existence of required files for redis-cache library
echo "Verifying redis-cache library files..."
# Check main library files
fd -t f . "libs/redis-cache" -x echo "Found: {}"
# Check tsconfig
if [ -f "libs/redis-cache/tsconfig.lib.json" ]; then
echo "Found tsconfig.lib.json"
else
echo "Missing tsconfig.lib.json"
fi
# Check entry file
if [ -f "libs/redis-cache/src/index.ts" ]; then
echo "Found index.ts"
else
echo "Missing index.ts"
fi
Length of output: 451
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.
좋네요.
혹시 캐시를 invalidate 할 수 있는 방법이 있을까요?
공지가 수정된다던지...
지금 보니까 캐시를 사용할 때, endpoint를 기준으로만 저장을 하네요. 조금 수정이 필요하기는 할 듯 |
Fixes #117
Pull request
개요
PR Checklist
Summary by CodeRabbit