MCPcopy
hub / github.com/ory/hydra / flushInactiveTokens

Method flushInactiveTokens

persistence/sql/persister_oauth2.go:371–403  ·  view source on GitHub ↗
(ctx context.Context, notAfter time.Time, limit int, batchSize int, table tableName, lifespan time.Duration)

Source from the content-addressed store, hash-verified

369}
370
371func (p *Persister) flushInactiveTokens(ctx context.Context, notAfter time.Time, limit int, batchSize int, table tableName, lifespan time.Duration) (err error) {
372 /* #nosec G201 table is static */
373 // The value of notAfter should be the minimum between input parameter and token max expire based on its configured age
374 requestMaxExpire := time.Now().Add(-lifespan)
375 if requestMaxExpire.Before(notAfter) {
376 notAfter = requestMaxExpire
377 }
378
379 totalDeletedCount := 0
380 for deletedRecords := batchSize; totalDeletedCount < limit && deletedRecords == batchSize; {
381 d := batchSize
382 if limit-totalDeletedCount < batchSize {
383 d = limit - totalDeletedCount
384 }
385 // Delete in batches
386 // The outer SELECT is necessary because our version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery
387 deletedRecords, err = p.Connection(ctx).RawQuery(
388 fmt.Sprintf(`DELETE FROM %s WHERE signature in (
389 SELECT signature FROM (SELECT signature FROM %s hoa WHERE requested_at < ? and nid = ? ORDER BY requested_at LIMIT %d ) as s
390 )`, OAuth2RequestSQL{Table: table}.TableName(), OAuth2RequestSQL{Table: table}.TableName(), d),
391 notAfter,
392 p.NetworkID(ctx),
393 ).ExecWithCount()
394 totalDeletedCount += deletedRecords
395
396 if err != nil {
397 break
398 }
399 p.l.Debugf("Flushing tokens...: %d/%d", totalDeletedCount, limit)
400 }
401 p.l.Debugf("Flush Refresh Tokens flushed_records: %d", totalDeletedCount)
402 return sqlcon.HandleError(err)
403}
404
405func toEventOptions(requester fosite.Requester) []trace.EventOption {
406 sub := ""

Callers 2

Implementers 1

BasePersisterpersistence/sql/persister.go

Calls 6

ConnectionMethod · 0.95
DebugfMethod · 0.80
AddMethod · 0.65
NowMethod · 0.65
NetworkIDMethod · 0.65
TableNameMethod · 0.45

Tested by

no test coverage detected