Skip to content

Commit 125ce82

Browse files
committed
fix: proto dependency
1 parent fcd1bed commit 125ce82

File tree

6 files changed

+34
-366
lines changed

6 files changed

+34
-366
lines changed

apps/matching-service/go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ require (
1111
github.com/redis/go-redis/v9 v9.6.2
1212
google.golang.org/grpc v1.67.1
1313
google.golang.org/protobuf v1.35.1
14+
proto v0.0.0-00010101000000-000000000000
1415
)
1516

1617
require (

apps/matching-service/processes/findmatches.go

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
// Find the first matching user from the front on the queue, based on topics, then difficulty.
15-
func findMatchingUsers(tx *redis.Tx, currentUsername string, ctx context.Context) (*models.MatchFound, error) {
15+
func findMatchingUser(tx *redis.Tx, currentUsername string, ctx context.Context) (*models.MatchFound, error) {
1616
currentUser, err := databases.GetUserDetails(tx, currentUsername, ctx)
1717
if err != nil {
1818
return nil, err
@@ -153,14 +153,23 @@ func doTopicMatching(tx *redis.Tx, ctx context.Context, currentUser *models.Matc
153153

154154
// Iterate through the queue to find a match, so a user in the queue the longest is more likely to be matched.
155155
var foundUsers []string
156-
for _, otherUser := range potentialMatches {
157-
if otherUser == currentUser.Username {
156+
for _, otherUsername := range potentialMatches {
157+
if otherUsername == currentUser.Username {
158158
continue
159159
}
160160

161+
// Include users without any difficulty selected
162+
otherUser, err := databases.GetUserDetails(tx, otherUsername, ctx)
163+
if err != nil {
164+
return nil, err
165+
}
166+
if len(otherUser.Topics) == 0 {
167+
foundUsers = append(foundUsers, otherUsername)
168+
}
169+
161170
// other user has matching topic
162-
if _, ok := sameTopicUsers[otherUser]; ok {
163-
foundUsers = append(foundUsers, otherUser)
171+
if _, ok := sameTopicUsers[otherUsername]; ok {
172+
foundUsers = append(foundUsers, otherUsername)
164173
break
165174
}
166175
}
@@ -181,14 +190,23 @@ func doDifficultyMatching(tx *redis.Tx, ctx context.Context, currentUser *models
181190

182191
// Iterate through the queue to find a match, so a user in the queue the longest is more likely to be matched.
183192
var foundUsers []string
184-
for _, otherUser := range potentialMatches {
185-
if otherUser == currentUser.Username {
193+
for _, otherUsername := range potentialMatches {
194+
if otherUsername == currentUser.Username {
186195
continue
187196
}
188197

189-
// other user has matching difficulty
190-
if _, ok := sameDifficultyUsers[otherUser]; ok {
191-
foundUsers = append(foundUsers, otherUser)
198+
// Include users without any difficulty selected
199+
otherUser, err := databases.GetUserDetails(tx, otherUsername, ctx)
200+
if err != nil {
201+
return nil, err
202+
}
203+
if len(otherUser.Topics) == 0 {
204+
foundUsers = append(foundUsers, otherUsername)
205+
}
206+
207+
// other user has matching difficulty or has no difficulty
208+
if _, ok := sameDifficultyUsers[otherUsername]; ok {
209+
foundUsers = append(foundUsers, otherUsername)
192210
break
193211
}
194212
}

apps/matching-service/processes/performmatches.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import (
88
"log"
99
"matching-service/databases"
1010
"matching-service/models"
11-
pb "matching-service/proto"
11+
pb "proto/questionmatching"
12+
1213
"matching-service/servers"
1314

1415
"github.com/redis/go-redis/v9"
@@ -39,7 +40,7 @@ func PerformMatching(rdb *redis.Client, matchRequest models.MatchRequest, ctx co
3940
defer databases.PrintMatchingQueue(tx, "After Matchmaking", ctx)
4041

4142
// Find a matching user if any
42-
matchFound, err = findMatchingUsers(tx, currentUsername, ctx)
43+
matchFound, err = findMatchingUser(tx, currentUsername, ctx)
4344
if err != nil {
4445
if errors.Is(err, models.NoMatchFound) {
4546
return nil
@@ -119,7 +120,7 @@ func queryQuestionService(ctx context.Context, matchFound *models.MatchFound) *m
119120
User: matchFound.User,
120121
MatchedUser: matchFound.MatchedUser,
121122
MatchedTopics: matchFound.MatchedTopics,
122-
QuestionDocRefID: question.QuestionName,
123+
QuestionDocRefID: question.QuestionDocRefId,
123124
QuestionName: question.QuestionName,
124125
QuestionDifficulty: question.QuestionDifficulty,
125126
QuestionTopics: question.QuestionTopics,

apps/matching-service/proto/questionmatching.pb.go

Lines changed: 0 additions & 230 deletions
This file was deleted.

0 commit comments

Comments
 (0)