-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #236 from DongHoonYu96/feature-be-#219#229
[BE] feat#219 redis ๋ฉ๋ชจ๋ฆฌ ๊ด๋ฆฌ ๊ตฌํ
- Loading branch information
Showing
19 changed files
with
486 additions
and
86 deletions.
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`); | ||
} | ||
|
||
return of(result); | ||
} | ||
} |
Oops, something went wrong.