@@ -2,6 +2,7 @@ import { client, logQueueStatus } from '@/lib/db';
2
2
import { POOL_INDEX , STREAM_GROUP , STREAM_NAME , STREAM_WORKER } from '@/lib/db/constants' ;
3
3
import { decodePoolTicket , getPoolKey , getStreamId } from '@/lib/utils' ;
4
4
import { getMatchItems } from '@/services' ;
5
+ import { IMatchType } from '@/types' ;
5
6
import { MATCHING_EVENT } from '@/ws/events' ;
6
7
7
8
import { connectClient , sendNotif } from './common' ;
@@ -41,7 +42,9 @@ async function processMatch(
41
42
redisClient : typeof client ,
42
43
{ requestorUserId, requestorStreamId, requestorSocketPort } : RequestorParams ,
43
44
matches : Awaited < ReturnType < ( typeof client ) [ 'ft' ] [ 'search' ] > > ,
44
- searchIdentifier ?: string
45
+ searchIdentifier ?: IMatchType ,
46
+ topic ?: string ,
47
+ difficulty ?: string
45
48
) {
46
49
if ( matches . total > 0 ) {
47
50
for ( const matched of matches . documents ) {
@@ -70,10 +73,17 @@ async function processMatch(
70
73
] ) ;
71
74
72
75
// Notify both sockets
73
- const { ...matchItems } = getMatchItems ( { userId1 : requestorUserId , userId2 : matchedUserId } ) ;
76
+ const { ...matchItems } = await getMatchItems (
77
+ searchIdentifier ,
78
+ topic ,
79
+ difficulty ,
80
+ requestorUserId ,
81
+ matchedUserId
82
+ ) ;
83
+ logger . info ( `Generated Match - ${ JSON . stringify ( matchItems ) } ` ) ;
74
84
75
- sendNotif ( [ matchedSocketPort , requestorSocketPort ] , MATCHING_EVENT . SUCCESS , matchItems ) ;
76
- sendNotif ( [ matchedSocketPort , requestorSocketPort ] , MATCHING_EVENT . DISCONNECT ) ;
85
+ sendNotif ( [ requestorSocketPort , matchedSocketPort ] , MATCHING_EVENT . SUCCESS , matchItems ) ;
86
+ sendNotif ( [ requestorSocketPort , matchedSocketPort ] , MATCHING_EVENT . DISCONNECT ) ;
77
87
78
88
await logQueueStatus ( logger , redisClient , `Queue Status After Matching: <PLACEHOLDER>` ) ;
79
89
return true ;
@@ -86,6 +96,7 @@ async function processMatch(
86
96
87
97
async function match ( ) {
88
98
const redisClient = await connectClient ( client ) ;
99
+
89
100
const stream = await redisClient . xReadGroup (
90
101
STREAM_GROUP ,
91
102
STREAM_WORKER ,
@@ -143,7 +154,9 @@ async function match() {
143
154
redisClient ,
144
155
requestorParams ,
145
156
exactMatches ,
146
- 'exact match'
157
+ 'exact match' ,
158
+ topic ,
159
+ difficulty
147
160
) ;
148
161
149
162
if ( exactMatchFound || ! topic || ! difficulty ) {
@@ -161,7 +174,9 @@ async function match() {
161
174
redisClient ,
162
175
requestorParams ,
163
176
topicMatches ,
164
- 'topic'
177
+ 'topic' ,
178
+ topic ,
179
+ difficulty
165
180
) ;
166
181
167
182
if ( topicMatchFound ) {
@@ -178,7 +193,9 @@ async function match() {
178
193
redisClient ,
179
194
requestorParams ,
180
195
difficultyMatches ,
181
- 'difficulty'
196
+ 'difficulty' ,
197
+ topic ,
198
+ difficulty
182
199
) ;
183
200
184
201
if ( ! hasDifficultyMatch ) {
0 commit comments