Skip to content

Commit 52afc90

Browse files
committed
chore: temp update redis calls
1 parent add2e90 commit 52afc90

File tree

7 files changed

+290
-66
lines changed

7 files changed

+290
-66
lines changed

api/frontend.proto

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ message GetIndexedTicketCountResponse{
152152
int32 count =1;
153153
}
154154

155+
message GetExpiredTicketIdsRequest {
156+
int32 limit = 1;
157+
}
158+
159+
message GetExpiredTicketIdsResponse {
160+
repeated string ticket_ids = 1;
161+
}
162+
163+
155164
// The FrontendService implements APIs to manage and query status of a Tickets.
156165
service FrontendService {
157166
// CreateTicket assigns an unique TicketId to the input Ticket and record it in state storage.
@@ -271,4 +280,12 @@ service FrontendService {
271280
body: "*"
272281
};
273282
}
283+
284+
// GetExpiredTicketIds get the expired tickets limited by the specified number
285+
rpc GetExpiredTicketIds(GetExpiredTicketIdsRequest) returns (GetExpiredTicketIdsResponse) {
286+
option (google.api.http) = {
287+
post: "/v1/frontendservice/tickets/expired"
288+
body: "*"
289+
};
290+
}
274291
}

api/frontend.swagger.json

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -425,14 +425,14 @@
425425
}
426426
},
427427
"/v1/frontendservice/tickets/expired": {
428-
"get": {
429-
"summary": "GetExpiredTickets returns the ticket Ids corresponding to tickets outside the valid window",
430-
"operationId": "FrontendService_GetExpiredTickets",
428+
"post": {
429+
"summary": "GetExpiredTicketIds get the expired tickets limited by the specified number",
430+
"operationId": "FrontendService_GetExpiredTicketIds",
431431
"responses": {
432432
"200": {
433433
"description": "A successful response.",
434434
"schema": {
435-
"$ref": "#/definitions/openmatchGetExpiredTicketsResponse"
435+
"$ref": "#/definitions/openmatchGetExpiredTicketIdsResponse"
436436
}
437437
},
438438
"404": {
@@ -451,12 +451,12 @@
451451
},
452452
"parameters": [
453453
{
454-
"name": "limit",
455-
"description": "The limit on how many ticket Ids to return",
456-
"in": "query",
457-
"required": false,
458-
"type": "integer",
459-
"format": "int32"
454+
"name": "body",
455+
"in": "body",
456+
"required": true,
457+
"schema": {
458+
"$ref": "#/definitions/openmatchGetExpiredTicketIdsRequest"
459+
}
460460
}
461461
],
462462
"tags": [
@@ -711,15 +711,23 @@
711711
}
712712
}
713713
},
714-
"openmatchGetExpiredTicketsResponse": {
714+
"openmatchGetExpiredTicketIdsRequest": {
715+
"type": "object",
716+
"properties": {
717+
"limit": {
718+
"type": "integer",
719+
"format": "int32"
720+
}
721+
}
722+
},
723+
"openmatchGetExpiredTicketIdsResponse": {
715724
"type": "object",
716725
"properties": {
717726
"ticket_ids": {
718727
"type": "array",
719728
"items": {
720729
"type": "string"
721-
},
722-
"description": "Expired TicketIds of generated Tickets to be deleted."
730+
}
723731
}
724732
}
725733
},

internal/app/frontend/frontend_service.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,3 +496,17 @@ func (s *frontendService) GetTickets(ctx context.Context, req *pb.GetTicketsRequ
496496

497497
return resp, nil
498498
}
499+
500+
// GetExpiredTicketIds get the expired tickets limited by the specified number
501+
func (s *frontendService) GetExpiredTicketIds(ctx context.Context, req *pb.GetExpiredTicketIdsRequest) (*pb.GetExpiredTicketIdsResponse, error) {
502+
ticketIds, err := s.store.GetExpiredTicketIDs(ctx, int(req.GetLimit()))
503+
if err != nil {
504+
return nil, err
505+
}
506+
507+
response := &pb.GetExpiredTicketIdsResponse{
508+
TicketIds: ticketIds,
509+
}
510+
511+
return response, nil
512+
}

internal/statestore/ticket.go

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,6 @@ func (rb *redisBackend) IndexTicket(ctx context.Context, ticket *pb.Ticket) erro
203203
}
204204
defer handleConnectionClose(&redisConn)
205205

206-
err = redisConn.Send("SADD", allTickets, ticket.Id)
207-
if err != nil {
208-
err = errors.Wrapf(err, "failed to add ticket to all tickets, id: %s", ticket.Id)
209-
return status.Errorf(codes.Internal, "%v", err)
210-
}
211-
212206
ticketTTL := getTicketReleaseTimeout(rb.cfg)
213207
expiry := time.Now().Add(ticketTTL).UnixNano()
214208
err = redisConn.Send("ZADD", allTicketsWithTTL, expiry, ticket.Id)
@@ -228,12 +222,6 @@ func (rb *redisBackend) DeindexTicket(ctx context.Context, id string) error {
228222
}
229223
defer handleConnectionClose(&redisConn)
230224

231-
err = redisConn.Send("SREM", allTickets, id)
232-
if err != nil {
233-
err = errors.Wrapf(err, "failed to remove ticket from all tickets, id: %s", id)
234-
return status.Errorf(codes.Internal, "%v", err)
235-
}
236-
237225
err = redisConn.Send("ZREM", allTicketsWithTTL, id)
238226
if err != nil {
239227
err = errors.Wrapf(err, "failed to remove ticket from all tickets, id: %s", id)
@@ -252,18 +240,11 @@ func (rb *redisBackend) DeindexTickets(ctx context.Context, ids []string) error
252240
defer handleConnectionClose(&redisConn)
253241

254242
args := make([]any, len(ids)+1)
255-
args[0] = allTickets
243+
args[0] = allTicketsWithTTL
256244
for i, id := range ids {
257245
args[i+1] = id
258246
}
259247

260-
err = redisConn.Send("SREM", args...)
261-
if err != nil {
262-
err = errors.Wrapf(err, "failed to remove ticket from all tickets, id: %v", ids)
263-
return status.Errorf(codes.Internal, "%v", err)
264-
}
265-
266-
args[0] = allTicketsWithTTL
267248
err = redisConn.Send("ZREM", args...)
268249
if err != nil {
269250
err = errors.Wrapf(err, "failed to remove ticket from all tickets, id: %v", ids)

pkg/pb/frontend.pb.go

Lines changed: 131 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)