From 49eb13b2c147e63b342854f21ae36288570fa1b9 Mon Sep 17 00:00:00 2001 From: songbuild00 Date: Mon, 2 Dec 2024 11:25:58 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20=EC=B1=84=EC=A0=90=20=EC=98=A4?= =?UTF-8?q?=EB=A5=98=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../game/redis/subscribers/timer.subscriber.ts | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/BE/src/game/redis/subscribers/timer.subscriber.ts b/BE/src/game/redis/subscribers/timer.subscriber.ts index ab5af5b..2a43301 100644 --- a/BE/src/game/redis/subscribers/timer.subscriber.ts +++ b/BE/src/game/redis/subscribers/timer.subscriber.ts @@ -65,7 +65,7 @@ export class TimerSubscriber extends RedisSubscriber { const selectAnswer = this.calculateAnswer( player.positionX, player.positionY, - quizList.length + parseInt(quiz.choiceCount) ); // this.logger.verbose(selectAnswer); @@ -167,8 +167,8 @@ export class TimerSubscriber extends RedisSubscriber { } private calculateAnswer(positionX: string, positionY: string, quizLen: number): number { - const x = parseFloat(positionX); - const y = parseFloat(positionY); + const x = parseFloat(positionY); + const y = parseFloat(positionX); // 행의 개수 계산 (2열 고정이므로 총 개수의 절반을 올림) const rows = Math.ceil(quizLen / 2); @@ -177,21 +177,12 @@ export class TimerSubscriber extends RedisSubscriber { const rowIndex = Math.floor(y * rows); // X 좌표로 왼쪽/오른쪽 결정 - const colIndex = x < 0.5 ? 0 : 1; + const colIndex = Math.round(x); // 최종 선택지 번호 계산 const answer = rowIndex * 2 + colIndex + 1; // 실제 선택지 범위를 벗어나지 않도록 보정 return Math.min(answer, quizLen); - // return ( - // Math.round( - // parseFloat(positionX) + Math.floor(parseFloat(positionY) * Math.ceil(quizLen / 2)) - // ) * 2 - // ); - // if (parseFloat(positionY) < 0.5) { - // return parseFloat(positionX) < 0.5 ? 1 : 2; - // } - // return parseFloat(positionX) < 0.5 ? 3 : 4; } } From 402c90713365afc6f658feac206db93a340f71ed Mon Sep 17 00:00:00 2001 From: songbuild00 Date: Mon, 2 Dec 2024 16:08:19 +0900 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20TTL=20=EA=B4=80=EB=A6=AC=20Cron=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/game/redis/game-redis-memory.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BE/src/game/redis/game-redis-memory.service.ts b/BE/src/game/redis/game-redis-memory.service.ts index 5f86f46..d8669b7 100644 --- a/BE/src/game/redis/game-redis-memory.service.ts +++ b/BE/src/game/redis/game-redis-memory.service.ts @@ -22,7 +22,7 @@ export class GameRedisMemoryService { * TTL 관리를 위한 스케줄러 * 배치 처리로 블로킹 최소화 */ - @Cron(CronExpression.EVERY_MINUTE) + // @Cron(CronExpression.EVERY_MINUTE) async manageTTL(): Promise { try { // SCAN으로 활성 방 목록을 배치로 처리 From 356c0b4fade8bb6f0d972ccc7e3b8eb7328ece3c Mon Sep 17 00:00:00 2001 From: songbuild00 Date: Mon, 2 Dec 2024 16:29:02 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=ED=94=8C=EB=A0=88=EC=9D=B4=EC=96=B4?= =?UTF-8?q?=20=ED=82=A4=EC=97=90=20TTL=20=EC=84=A4=EC=A0=95=ED=95=B4?= =?UTF-8?q?=EC=A3=BC=EB=8D=98=20=EB=B6=80=EB=B6=84=20=EC=A3=BC=EC=84=9D=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/game/service/game.room.service.ts | 42 ++++++++++++------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/BE/src/game/service/game.room.service.ts b/BE/src/game/service/game.room.service.ts index 581104f..a44755a 100644 --- a/BE/src/game/service/game.room.service.ts +++ b/BE/src/game/service/game.room.service.ts @@ -18,7 +18,7 @@ import { TraceClass } from '../../common/interceptor/SocketEventLoggerIntercepto export class GameRoomService { private readonly logger = new Logger(GameRoomService.name); private readonly INACTIVE_THRESHOLD = 30 * 60 * 1000; // 30분 30 * 60 * 1000; - private readonly PLAYER_GRACE_PERIOD = 10; // 10초 + // private readonly PLAYER_GRACE_PERIOD = 10; // 10초 constructor( @InjectRedis() private readonly redis: Redis, @@ -215,7 +215,7 @@ export class GameRoomService { disconnected: '1', disconnectedAt: Date.now().toString() }); - pipeline.expire(REDIS_KEY.PLAYER(clientId), this.PLAYER_GRACE_PERIOD); + // pipeline.expire(REDIS_KEY.PLAYER(clientId), this.PLAYER_GRACE_PERIOD); await pipeline.exec(); @@ -233,7 +233,7 @@ export class GameRoomService { const remainingPlayers = await this.redis.scard(roomPlayersKey); // 4. 플레이어 관련 모든 키에 TTL 설정 - await this.setTTLForPlayerKeys(clientId); + // await this.setTTLForPlayerKeys(clientId); if (remainingPlayers === 0) { // 마지막 플레이어가 나간 경우 @@ -277,24 +277,24 @@ export class GameRoomService { /** * 플레이어 관련 모든 데이터에 TTL 설정 */ - private async setTTLForPlayerKeys(clientId: string): Promise { - let cursor = '0'; - const pattern = `Player:${clientId}:*`; - const pipeline = this.redis.pipeline(); - - do { - // SCAN으로 플레이어 관련 키들을 배치로 찾기 - const [nextCursor, keys] = await this.redis.scan(cursor, 'MATCH', pattern, 'COUNT', 100); - cursor = nextCursor; - - // 찾은 모든 키에 TTL 설정 - for (const key of keys) { - pipeline.expire(key, this.PLAYER_GRACE_PERIOD); - } - } while (cursor !== '0'); - - await pipeline.exec(); - } + // private async setTTLForPlayerKeys(clientId: string): Promise { + // let cursor = '0'; + // const pattern = `Player:${clientId}:*`; + // const pipeline = this.redis.pipeline(); + // + // do { + // // SCAN으로 플레이어 관련 키들을 배치로 찾기 + // const [nextCursor, keys] = await this.redis.scan(cursor, 'MATCH', pattern, 'COUNT', 100); + // cursor = nextCursor; + // + // // 찾은 모든 키에 TTL 설정 + // for (const key of keys) { + // pipeline.expire(key, this.PLAYER_GRACE_PERIOD); + // } + // } while (cursor !== '0'); + // + // await pipeline.exec(); + // } async kickRoom(kickRoomDto: KickRoomDto, clientId: string) { const { gameId, kickPlayerId } = kickRoomDto;