deleteExpiredSessions method
Deletes the session where ServerSideSession.expiresAt has elapsed, or where the session has not been used in since ServerSideSession.expireAfterUnusedFor expired it.
Implementation
Future<void> deleteExpiredSessions(
final Session session, {
/// Whether to delete sessions which [ServerSideSession.expiresAt] is in the past.
final bool deleteExpired = true,
/// Whether to delete sessions which have not been used for [ServerSideSession.expireAfterUnusedFor].
final bool deleteInactive = true,
final Transaction? transaction,
}) async {
if (deleteExpired) {
await ServerSideSession.db.deleteWhere(
session,
where: (final t) => t.expiresAt < clock.now(),
transaction: transaction,
);
}
if (deleteInactive) {
await session.db.unsafeQuery(
'DELETE FROM ${ServerSideSession.t.tableName} WHERE '
'"${ServerSideSession.t.expireAfterUnusedFor.columnName}" IS NOT NULL AND '
'"${ServerSideSession.t.lastUsedAt.columnName}" + ("${ServerSideSession.t.expireAfterUnusedFor.columnName}" * INTERVAL \'1 millisecond\') < \'${SerializationManager.encode(clock.now())}\'',
transaction: transaction,
);
}
}