Skip to content

Commit e338131

Browse files
committed
chore: preallocate inmem maps
1 parent 44920c5 commit e338131

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

internal/app/query/cache.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func newTicketCache(b *appmain.Bindings, store statestore.Service) *cache {
125125
store: store,
126126
requests: make(chan *cacheRequest),
127127
startRunRequest: make(chan struct{}, 1),
128-
value: make(map[string]*pb.Ticket),
128+
value: make(map[string]*pb.Ticket, 100_000),
129129
update: updateTicketCache,
130130
}
131131

@@ -192,7 +192,7 @@ func newBackfillCache(b *appmain.Bindings, store statestore.Service) *cache {
192192
store: store,
193193
requests: make(chan *cacheRequest),
194194
startRunRequest: make(chan struct{}, 1),
195-
value: make(map[string]*pb.Backfill),
195+
value: make(map[string]*pb.Backfill, 50_000),
196196
update: updateBackfillCache,
197197
}
198198

internal/statestore/ticket.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func (rb *redisBackend) checkIfExpired(ctx context.Context, id string) (bool, er
188188

189189
score, err := redis.Float64(redisConn.Do("ZSCORE", allTicketsWithTTL, id))
190190
if errors.Is(err, redis.ErrNil) {
191-
logger.WithError(err).Errorf("Ticket id: %s not found", id)
191+
logger.WithError(err).Errorf("checkIfExpired: Ticket id: %s not found", id)
192192
return true, nil
193193
}
194194
if err != nil {
@@ -452,25 +452,27 @@ func (rb *redisBackend) GetTickets(ctx context.Context, ids []string) ([]*pb.Tic
452452
}
453453
r = append(r, t)
454454

455-
if t.Assignment == nil {
455+
if t.Assignment != nil {
456456
// if a ticket is assigned, its given an TTL and automatically de-indexed
457-
expiredKey, err := rb.checkIfExpired(ctx, t.Id)
458-
if err != nil {
459-
err = errors.Wrapf(err, "failed to check ticket expiry, %v", err)
460-
return nil, status.Errorf(codes.Internal, "%v", err)
461-
}
462-
463-
if expiredKey {
464-
continue
465-
}
466-
467-
expiry := time.Now().Add(ticketTTL).UnixNano()
468-
// update the indexed ticket's ttl. careful this might become slow.
469-
err = redisConn.Send("ZADD", allTicketsWithTTL, "XX", "CH", expiry, t.Id)
470-
if err != nil {
471-
err = errors.Wrapf(err, "failed to update ttl for ticket id: %s", t.Id)
472-
return nil, status.Errorf(codes.Internal, "%v", err)
473-
}
457+
continue
458+
}
459+
460+
expiredKey, err := rb.checkIfExpired(ctx, t.Id)
461+
if err != nil {
462+
err = errors.Wrapf(err, "failed to check ticket expiry, %v", err)
463+
return nil, status.Errorf(codes.Internal, "%v", err)
464+
}
465+
466+
if expiredKey {
467+
continue
468+
}
469+
470+
expiry := time.Now().Add(ticketTTL).UnixNano()
471+
// update the indexed ticket's ttl. careful this might become slow.
472+
err = redisConn.Send("ZADD", allTicketsWithTTL, "XX", "CH", expiry, t.Id)
473+
if err != nil {
474+
err = errors.Wrapf(err, "failed to update ttl for ticket id: %s", t.Id)
475+
return nil, status.Errorf(codes.Internal, "%v", err)
474476
}
475477
}
476478
}

0 commit comments

Comments
 (0)