@@ -4,6 +4,7 @@ import { EventEmitter2 } from '@nestjs/event-emitter';
44import { SchedulerRegistry } from '@nestjs/schedule' ;
55import Redis from 'ioredis' ;
66
7+ import { AuthService } from '../../../auth/service/auth.service' ;
78import { UserService } from '../../user/service/user.service' ;
89import { ENTERING_GC_INTERVAL , ENTERING_SESSION_EXPIRY } from '../const/enterBooking.const' ;
910
@@ -12,6 +13,7 @@ export class EnterBookingService {
1213 private readonly redis : Redis | null ;
1314 constructor (
1415 private readonly redisService : RedisService ,
16+ private readonly authService : AuthService ,
1517 private readonly userService : UserService ,
1618 private readonly eventEmitter : EventEmitter2 ,
1719 private readonly schedulerRegistry : SchedulerRegistry ,
@@ -78,7 +80,22 @@ export class EnterBookingService {
7880
7981 private async removeExpiredSessions ( eventId : number ) {
8082 const expiryTimestamp = Date . now ( ) - ENTERING_SESSION_EXPIRY ;
81- await this . redis . zremrangebyscore ( `entering:${ eventId } ` , 0 , expiryTimestamp ) ;
83+ const key = `entering:${ eventId } ` ;
84+
85+ const multi = this . redis . multi ( ) ;
86+ multi . zrangebyscore ( key , 0 , expiryTimestamp ) ;
87+ multi . zremrangebyscore ( key , 0 , expiryTimestamp ) ;
88+
89+ const results = ( await multi . exec ( ) ) as [ [ Error | null , string [ ] ] , [ Error | null , number ] ] ;
90+
91+ if ( results [ 0 ] [ 0 ] ) {
92+ throw results [ 0 ] [ 0 ] ;
93+ }
94+ const expiredSessions = results [ 0 ] [ 1 ] ;
95+
96+ expiredSessions . forEach ( ( sid : string ) => {
97+ this . authService . setUserStatusLogin ( sid ) ;
98+ } ) ;
8299 }
83100
84101 async getAllEnteringSids ( eventId : number ) {
0 commit comments