-
Notifications
You must be signed in to change notification settings - Fork 5
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
[BE] feat#219 redis 메모리 관리 구현 #236
Merged
DongHoonYu96
merged 9 commits into
boostcampwm-2024:dev-be
from
DongHoonYu96:feature-be-#219#229
Nov 21, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2f2e752
refactor: [BE] redis구독 폴더 위치 game내로 변경
DongHoonYu96 29eb46e
fix: [BE] quizset chace ttl 30분으로 설정
DongHoonYu96 cd2a3f1
feat: [BE] redis TTL 설정
DongHoonYu96 fcbe6a0
refactor: [BE] TTL 설정 비동기, batch로 수정
DongHoonYu96 fa0f460
feat: [BE] 퇴장시 redis에서 Room data 삭제, gateway요청시 Activity update 구현
DongHoonYu96 185a8c1
fix: [BE] 연결끊은 즉시 삭제 -> 나갔다는 이벤트를 못뿌려주는 버그 수정
DongHoonYu96 edd55af
chore: [BE] test 의존성설정
DongHoonYu96 f3a94b5
feat: [BE] player 퇴장시 관련 data 모두삭제
DongHoonYu96 30d6b36
feat: [BE] 비활성 방 체크 주기적 실행
DongHoonYu96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,70 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { AppController } from './app.controller'; | ||
import { AppService } from './app.service'; | ||
import { GameModule } from './game/game.module'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { RedisModule } from '@nestjs-modules/ioredis'; | ||
import { ConfigModule } from '@nestjs/config'; | ||
import { QuizSetModel } from './quiz-set/entities/quiz-set.entity'; | ||
import { QuizModel } from './quiz-set/entities/quiz.entity'; | ||
import { QuizChoiceModel } from './quiz-set/entities/quiz-choice.entity'; | ||
import { UserModel } from './user/entities/user.entity'; | ||
import { UserQuizArchiveModel } from './user/entities/user-quiz-archive.entity'; | ||
import { InitDBModule } from './InitDB/InitDB.module'; | ||
import { UserModule } from './user/user.module'; | ||
import { QuizSetModule } from './quiz-set/quiz-set.module'; | ||
import { WaitingRoomModule } from './waiting-room/waiting-room.module'; | ||
import { TimeController } from './time/time.controller'; | ||
import { TimeModule } from './time/time.module'; | ||
import { AuthModule } from './auth/auth.module'; | ||
|
||
@Module({ | ||
imports: [ | ||
ConfigModule.forRoot({ | ||
envFilePath: '../.env', | ||
isGlobal: true | ||
}), | ||
GameModule, | ||
TypeOrmModule.forRoot({ | ||
type: 'mysql', | ||
host: process.env.DB_HOST || 'localhost', | ||
port: +process.env.DB_PORT || 3306, | ||
username: process.env.DB_USER || 'root', | ||
password: process.env.DB_PASSWD || 'test', | ||
database: process.env.DB_NAME || 'test_db', | ||
entities: [QuizSetModel, QuizModel, QuizChoiceModel, UserModel, UserQuizArchiveModel], | ||
synchronize: process.env.DEV ? true : false, // 개발 모드에서만 활성화 | ||
logging: true, // 모든 쿼리 로깅 | ||
logger: 'advanced-console' | ||
// extra: { | ||
// // 글로벌 batch size 설정 | ||
// maxBatchSize: 100 | ||
// } | ||
}), | ||
RedisModule.forRoot({ | ||
type: 'single', | ||
url: process.env.REDIS_URL || 'redis://localhost:6379' | ||
}), | ||
QuizSetModule, | ||
UserModule, | ||
InitDBModule, | ||
WaitingRoomModule, | ||
TimeModule | ||
AuthModule | ||
], | ||
controllers: [AppController, TimeController], | ||
providers: [AppService] | ||
}) | ||
export class AppModule {} | ||
import { ClassSerializerInterceptor, Module } from '@nestjs/common'; | ||
import { AppController } from './app.controller'; | ||
import { AppService } from './app.service'; | ||
import { GameModule } from './game/game.module'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { RedisModule } from '@nestjs-modules/ioredis'; | ||
import { ConfigModule } from '@nestjs/config'; | ||
import { QuizSetModel } from './quiz-set/entities/quiz-set.entity'; | ||
import { QuizModel } from './quiz-set/entities/quiz.entity'; | ||
import { QuizChoiceModel } from './quiz-set/entities/quiz-choice.entity'; | ||
import { UserModel } from './user/entities/user.entity'; | ||
import { UserQuizArchiveModel } from './user/entities/user-quiz-archive.entity'; | ||
import { InitDBModule } from './InitDB/InitDB.module'; | ||
import { UserModule } from './user/user.module'; | ||
import { QuizSetModule } from './quiz-set/quiz-set.module'; | ||
import { WaitingRoomModule } from './waiting-room/waiting-room.module'; | ||
import { TimeController } from './time/time.controller'; | ||
import { TimeModule } from './time/time.module'; | ||
import { AuthModule } from './auth/auth.module'; | ||
import { ScheduleModule } from '@nestjs/schedule'; | ||
import { GameRedisMemoryService } from './game/redis/game-redis-memory.service'; | ||
import { APP_INTERCEPTOR } from '@nestjs/core'; | ||
|
||
@Module({ | ||
imports: [ | ||
ConfigModule.forRoot({ | ||
envFilePath: '../.env', | ||
isGlobal: true | ||
}), | ||
GameModule, | ||
// 스케줄러 모듈 추가 (Redis 메모리 관리 서비스의 @Cron 데코레이터 사용을 위해) | ||
ScheduleModule.forRoot(), | ||
TypeOrmModule.forRoot({ | ||
type: 'mysql', | ||
host: process.env.DB_HOST || 'localhost', | ||
port: +process.env.DB_PORT || 3306, | ||
username: process.env.DB_USER || 'root', | ||
password: process.env.DB_PASSWD || 'test', | ||
database: process.env.DB_NAME || 'test_db', | ||
entities: [QuizSetModel, QuizModel, QuizChoiceModel, UserModel, UserQuizArchiveModel], | ||
synchronize: process.env.DEV ? true : false, // 개발 모드에서만 활성화 | ||
logging: true, // 모든 쿼리 로깅 | ||
logger: 'advanced-console' | ||
// extra: { | ||
// // 글로벌 batch size 설정 | ||
// maxBatchSize: 100 | ||
// } | ||
}), | ||
RedisModule.forRoot({ | ||
type: 'single', | ||
url: process.env.REDIS_URL || 'redis://localhost:6379' | ||
}), | ||
QuizSetModule, | ||
UserModule, | ||
InitDBModule, | ||
WaitingRoomModule, | ||
TimeModule, | ||
AuthModule | ||
], | ||
controllers: [AppController, TimeController], | ||
providers: [ | ||
AppService, | ||
GameRedisMemoryService, | ||
{ | ||
provide: APP_INTERCEPTOR, | ||
useClass: ClassSerializerInterceptor | ||
} | ||
] | ||
}) | ||
export class AppModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// 활동 시간 업데이트는 비즈니스 로직과 분리 | ||
import { CallHandler, ExecutionContext, Injectable, Logger, NestInterceptor } from '@nestjs/common'; | ||
import { of } from 'rxjs'; | ||
import { GameRoomService } from '../service/game.room.service'; | ||
|
||
@Injectable() | ||
export class GameActivityInterceptor implements NestInterceptor { | ||
private readonly logger = new Logger(GameActivityInterceptor.name); | ||
|
||
constructor(private readonly gameRoomService: GameRoomService) {} | ||
|
||
async intercept(context: ExecutionContext, next: CallHandler) { | ||
// 핵심 로직 실행 전 | ||
const before = Date.now(); | ||
|
||
// 핵심 로직 실행 | ||
const result = await next.handle().toPromise(); | ||
|
||
// 활동 시간 업데이트 (부가 기능) | ||
const data = context.switchToWs().getData(); | ||
if (data.gameId) { | ||
await this.gameRoomService.updateRoomActivity(data.gameId); | ||
this.logger.debug(`Activity updated for room ${data.gameId} after ${Date.now() - before}ms`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: 지금 로그가 한글로 찍혀 있는 부분이 많아서 한글로 통일하면 좋을 것 같습니다! |
||
} | ||
|
||
return of(result); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
👍👍 좋습니다!