Skip to content

Commit 17cd591

Browse files
committed
chore: more accurate ticket expiry
1 parent 908ae03 commit 17cd591

File tree

8 files changed

+631
-82
lines changed

8 files changed

+631
-82
lines changed

internal/app/query/cache.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ func updateTicketCache(store statestore.Service, value interface{}) error {
147147

148148
t := time.Now()
149149
previousCount := len(tickets)
150-
currentAll, err := store.GetIndexedIDSet(context.Background())
150+
// get all indexed tickets within the valid time window
151+
currentAll, err := store.GetIndexedIDSetWithTTL(context.Background())
151152
if err != nil {
152153
return err
153154
}

internal/app/synchronizer/synchronizer_service.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,12 @@ Registration:
303303
if err != nil {
304304
logger.Errorf("Failed to clean up backfills, %s", err.Error())
305305
}
306+
307+
// TODO: this should probably be enabled much later like after a day of running without it for the transition for Prod
308+
err = s.store.CleanupTickets(ctx)
309+
if err != nil {
310+
logger.Errorf("Failed to clean up tickets, %s", err.Error())
311+
}
306312
}
307313

308314
///////////////////////////////////////

internal/statestore/instrumented.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,37 @@ func (is *instrumentedService) DeleteBackfillCompletely(ctx context.Context, id
210210
return is.s.DeleteBackfillCompletely(ctx, id)
211211
}
212212

213+
// GetIndexedTicketCount returns the current count of indexed tickets
213214
func (is *instrumentedService) GetIndexedTicketCount(ctx context.Context) (int, error) {
214215
ctx, span := trace.StartSpan(context.Background(), "statestore/instrumented.GetIndexedTicketCount")
215216
defer span.End()
216217
return is.s.GetIndexedTicketCount(ctx)
217218
}
219+
220+
// CleanupTickets removes expired tickets
221+
func (is *instrumentedService) CleanupTickets(ctx context.Context) error {
222+
_, span := trace.StartSpan(context.Background(), "statestore/instrumented.CleanupTickets")
223+
defer span.End()
224+
return is.s.CleanupTickets(ctx)
225+
}
226+
227+
// DeleteTicketCompletely performs a set of operations to remove the ticket and all related entries.
228+
func (is *instrumentedService) DeleteTicketCompletely(ctx context.Context, id string) error {
229+
_, span := trace.StartSpan(context.Background(), "statestore/instrumented.DeleteTicketCompletely")
230+
defer span.End()
231+
return is.s.DeleteTicketCompletely(ctx, id)
232+
}
233+
234+
// GetExpiredTicketIDs gets all ticket IDs which are expired
235+
func (is *instrumentedService) GetExpiredTicketIDs(ctx context.Context) ([]string, error) {
236+
ctx, span := trace.StartSpan(ctx, "statestore/instrumented.GetExpiredTicketIDs")
237+
defer span.End()
238+
return is.s.GetExpiredTicketIDs(ctx)
239+
}
240+
241+
// GetIndexedIDSetWithTTL returns the ids of all tickets currently indexed but within a given TTL.
242+
func (is *instrumentedService) GetIndexedIDSetWithTTL(ctx context.Context) (map[string]struct{}, error) {
243+
ctx, span := trace.StartSpan(ctx, "statestore/instrumented.GetIndexedIDSetWithTTL")
244+
defer span.End()
245+
return is.s.GetIndexedIDSetWithTTL(ctx)
246+
}

internal/statestore/public.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,18 @@ type Service interface {
127127

128128
// GetIndexedTicketCount returns the current count of indexed tickets
129129
GetIndexedTicketCount(ctx context.Context) (int, error)
130+
131+
//CleanupTickets removes expired tickets
132+
CleanupTickets(ctx context.Context) error
133+
134+
// DeleteTicketCompletely performs a set of operations to remove the ticket and all related entries.
135+
DeleteTicketCompletely(ctx context.Context, id string) error
136+
137+
// GetExpiredTicketIDs gets all ticket IDs which are expired
138+
GetExpiredTicketIDs(ctx context.Context) ([]string, error)
139+
140+
// GetIndexedIDSetWithTTL returns the ids of all tickets currently indexed but within a given TTL.
141+
GetIndexedIDSetWithTTL(ctx context.Context) (map[string]struct{}, error)
130142
}
131143

132144
// New creates a Service based on the configuration.

0 commit comments

Comments
 (0)