fix: handle large terminated sessions caching with pagination to prevent RAM overflow;
feat: add paginated query for terminated sessions GUIDs with limit and offset; refactor: batch processing terminated sessions in Redis with pipeline; chore: log batch caching progress for terminated sessions; fix: set TTL for session termination cache keys (8 hours); refactor: update SQL query for terminated sessions to use pagination; fix: correct loop structure in auth service initialization
This commit is contained in:
@@ -508,15 +508,22 @@ func (q *Queries) GetSessionByGuid(ctx context.Context, guid string) (Session, e
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUnexpiredTerminatedSessionsGuids = `-- name: GetUnexpiredTerminatedSessionsGuids :many
|
||||
const getUnexpiredTerminatedSessionsGuidsPaginated = `-- name: GetUnexpiredTerminatedSessionsGuidsPaginated :many
|
||||
SELECT guid FROM sessions
|
||||
WHERE
|
||||
terminated IS TRUE AND
|
||||
last_refresh_exp_time > CURRENT_TIMESTAMP
|
||||
LIMIT $1::integer
|
||||
OFFSET $2
|
||||
`
|
||||
|
||||
func (q *Queries) GetUnexpiredTerminatedSessionsGuids(ctx context.Context) ([]pgtype.UUID, error) {
|
||||
rows, err := q.db.Query(ctx, getUnexpiredTerminatedSessionsGuids)
|
||||
type GetUnexpiredTerminatedSessionsGuidsPaginatedParams struct {
|
||||
BatchSize int32
|
||||
Offset int64
|
||||
}
|
||||
|
||||
func (q *Queries) GetUnexpiredTerminatedSessionsGuidsPaginated(ctx context.Context, arg GetUnexpiredTerminatedSessionsGuidsPaginatedParams) ([]pgtype.UUID, error) {
|
||||
rows, err := q.db.Query(ctx, getUnexpiredTerminatedSessionsGuidsPaginated, arg.BatchSize, arg.Offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user