@@ -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 { MATCH_SVC_EVENT } from '@/ws' ;
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,7 +73,15 @@ async function processMatch(
70
73
] ) ;
71
74
72
75
// Notify both sockets
73
- const { ...matchItems } = getMatchItems ( ) ;
76
+ const { ...matchItems } = await getMatchItems (
77
+ searchIdentifier ,
78
+ topic ,
79
+ difficulty ,
80
+ requestorUserId ,
81
+ matchedUserId
82
+ ) ;
83
+ logger . info ( `Generated Match - ${ JSON . stringify ( matchItems ) } ` ) ;
84
+
74
85
sendNotif ( [ requestorSocketPort , matchedSocketPort ] , MATCH_SVC_EVENT . SUCCESS , matchItems ) ;
75
86
sendNotif ( [ requestorSocketPort , matchedSocketPort ] , MATCH_SVC_EVENT . DISCONNECT ) ;
76
87
@@ -85,6 +96,7 @@ async function processMatch(
85
96
86
97
async function match ( ) {
87
98
const redisClient = await connectClient ( client ) ;
99
+
88
100
const stream = await redisClient . xReadGroup (
89
101
STREAM_GROUP ,
90
102
STREAM_WORKER ,
@@ -142,7 +154,9 @@ async function match() {
142
154
redisClient ,
143
155
requestorParams ,
144
156
exactMatches ,
145
- 'exact match'
157
+ 'exact match' ,
158
+ topic ,
159
+ difficulty
146
160
) ;
147
161
148
162
if ( exactMatchFound || ! topic || ! difficulty ) {
@@ -160,7 +174,9 @@ async function match() {
160
174
redisClient ,
161
175
requestorParams ,
162
176
topicMatches ,
163
- 'topic'
177
+ 'topic' ,
178
+ topic ,
179
+ difficulty
164
180
) ;
165
181
166
182
if ( topicMatchFound ) {
@@ -177,7 +193,9 @@ async function match() {
177
193
redisClient ,
178
194
requestorParams ,
179
195
difficultyMatches ,
180
- 'difficulty'
196
+ 'difficulty' ,
197
+ topic ,
198
+ difficulty
181
199
) ;
182
200
183
201
if ( ! hasDifficultyMatch ) {
0 commit comments