-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
I noticed that janitor $DSN --requests cleans up hydra_oauth2_authentication_request and hydra_oauth2_consent_request tables, but not hydra_oauth2_authentication_session. That latter one is the second largest table in our database right now. It does not seem to be a reason to keep those rows around.
Describe the solution you'd like
Remove the rows from hydra_oauth2_authentication_session that are no longer needed.
- We should not delete a row if there is a foreign key to it from either
hydra_oauth2_authentication_requestorhydra_oauth2_consent_request - We should not delete a row if the session has not yet expired
Additional context
The two queries to clean up hydra_oauth2_authentication_request and hydra_oauth2_consent_request tables are placed here. It seems fine to me to follow them by a new query to clean up the sessions as well:
var ls consent.LoginSession
err = p.Connection(ctx).RawQuery(fmt.Sprintf(`
DELETE
FROM %[1]s
WHERE NOT EXISTS
(
SELECT NULL
FROM %[2]s
WHERE %[2]s.login_session_id = %[1]s.id
)
AND NOT EXISTS
(
SELECT NULL
FROM %[3]s
WHERE %[3]s.login_session_id = %[1]s.id
)
AND authenticated_at < ?
AND authenticated_at < ?
`,
(&ls).TableName(),
(&lr).TableName(),
(&cr).TableName()),
time.Now().Add(-p.config.ConsentRequestMaxAge()),
notAfter).Exec()I think time.Now().Add(-p.config.ConsentRequestMaxAge()) may not be the right constraint for sessions since they may be useable beyond the lifespan of consent challenges (or am I wrong?) but the rest should be fine.