@@ -58,21 +58,11 @@ async function processMatch(
58
58
continue ;
59
59
}
60
60
61
- const setPendingToFalse = async ( userId : string ) => {
62
- await redisClient . hSet ( `match:${ userId } ` , 'pending' , 'false' ) ;
63
- console . log ( `User ${ userId } is now in MATCHING state, pending set to false.` ) ;
64
- } ;
65
-
66
- await Promise . all ( [
67
- setPendingToFalse ( requestorUserId ) , // Set pending to false for requester
68
- setPendingToFalse ( matchedUserId ) , // Set pending to false for matched user
69
- ] ) ;
70
-
71
61
// To block cancellation
72
62
sendNotif ( [ matchedSocketPort ] , MATCHING_EVENT . MATCHING ) ;
63
+ await redisClient . hSet ( getPoolKey ( matchedUserId ) , 'pending' , 'false' ) ;
73
64
74
65
const matchedStreamId = getStreamId ( timestamp ) ;
75
-
76
66
logger . info ( `Found match: ${ JSON . stringify ( matched ) } ` ) ;
77
67
78
68
await Promise . all ( [
@@ -141,8 +131,9 @@ async function match() {
141
131
142
132
// To Block Cancellation
143
133
sendNotif ( [ requestorSocketPort ] , MATCHING_EVENT . MATCHING ) ;
134
+ await redisClient . hSet ( getPoolKey ( requestorUserId ) , 'pending' , 'false' ) ;
144
135
145
- const clause = [ `-@userId:(${ requestorUserId } )` ] ;
136
+ const clause = [ `-@userId:(${ requestorUserId } ) @pending:(true) ` ] ;
146
137
147
138
if ( difficulty ) {
148
139
clause . push ( `@difficulty:{${ difficulty } }` ) ;
@@ -176,7 +167,7 @@ async function match() {
176
167
// Match on Topic
177
168
const topicMatches = await redisClient . ft . search (
178
169
POOL_INDEX ,
179
- `@topic:{ ${ topic } } -@userId:( ${ requestorUserId } )` ,
170
+ clause . filter ( ( v ) => ! v . startsWith ( '@difficulty' ) ) . join ( ' ' ) ,
180
171
searchParams
181
172
) ;
182
173
const topicMatchFound = await processMatch (
@@ -195,7 +186,7 @@ async function match() {
195
186
// Match on Difficulty
196
187
const difficultyMatches = await redisClient . ft . search (
197
188
POOL_INDEX ,
198
- `@difficulty: ${ difficulty } -@userId:( ${ requestorUserId } )` ,
189
+ clause . filter ( ( v ) => ! v . startsWith ( '@topic' ) ) . join ( ' ' ) ,
199
190
searchParams
200
191
) ;
201
192
const hasDifficultyMatch = await processMatch (
@@ -209,14 +200,9 @@ async function match() {
209
200
210
201
if ( ! hasDifficultyMatch ) {
211
202
// To allow cancellation
203
+ await redisClient . hSet ( getPoolKey ( requestorUserId ) , 'pending' , 'true' ) ;
212
204
sendNotif ( [ requestorSocketPort ] , MATCHING_EVENT . PENDING ) ;
213
-
214
- const setPendingToTrue = async ( userId : string ) => {
215
- await redisClient . hSet ( `match:${ userId } ` , 'pending' , 'true' ) ;
216
- console . log ( `User ${ userId } is now in PENDING state, pending set to true.` ) ;
217
- } ;
218
-
219
- await setPendingToTrue ( requestorUserId ) ;
205
+ logger . info ( `${ requestorUserId } is now in mode ${ MATCHING_EVENT . PENDING } ` ) ;
220
206
}
221
207
}
222
208
}
0 commit comments