Skip to content

Commit ca7970e

Browse files
author
r.v.stupnikov
committed
feat: method Persister.FlushInactiveLoginSessions supports for limit
1 parent 3c21f1e commit ca7970e

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

persistence/sql/persister_consent.go

+19-14
Original file line numberDiff line numberDiff line change
@@ -447,26 +447,31 @@ func (p *Persister) FlushInactiveLoginSessions(ctx context.Context, _ time.Time,
447447

448448
// "hydra_oauth2_authentication_session"
449449
var ls consent.LoginSession
450-
return p.Connection(ctx).RawQuery(fmt.Sprintf(`
451-
DELETE
450+
query := fmt.Sprintf(`
451+
DELETE FROM %[1]s WHERE id in
452+
(SELECT id
452453
FROM %[1]s
453454
WHERE NOT EXISTS
454-
(
455-
SELECT NULL
456-
FROM %[2]s
457-
WHERE %[2]s.login_session_id = %[1]s.id
458-
)
455+
(
456+
SELECT NULL
457+
FROM %[2]s
458+
WHERE %[2]s.login_session_id = %[1]s.id
459+
)
459460
AND NOT EXISTS
460-
(
461-
SELECT NULL
462-
FROM %[3]s
463-
WHERE %[3]s.login_session_id = %[1]s.id
464-
)
461+
(
462+
SELECT NULL
463+
FROM %[3]s
464+
WHERE %[3]s.login_session_id = %[1]s.id
465+
)
466+
LIMIT %[4]d)
465467
`,
466468
(&ls).TableName(),
467469
(&lr).TableName(),
468-
(&cr).TableName()),
469-
).Exec()
470+
(&cr).TableName(),
471+
limit,
472+
)
473+
474+
return p.Connection(ctx).RawQuery(query).Exec()
470475
})
471476
}
472477

0 commit comments

Comments
 (0)