code: expired,dbal,clean (1 files)

This commit is contained in:
2025-12-26 01:34:35 +00:00
parent d91ac744a2
commit 366a682541

View File

@@ -2,30 +2,30 @@
* @file clean-expired.ts
* @description Clean expired sessions operation
*/
import type { Result } from '../types';
import type { InMemoryStore } from '../store/in-memory-store';
import type { Result } from '../../types'
import type { InMemoryStore } from '../../store/in-memory-store'
/**
* Clean up expired sessions
* @returns Number of sessions removed
*/
export async function cleanExpiredSessions(store: InMemoryStore): Promise<Result<number>> {
const now = new Date();
const expiredIds: string[] = [];
export const cleanExpiredSessions = async (store: InMemoryStore): Promise<Result<number>> => {
const now = new Date()
const expiredIds: string[] = []
for (const [id, session] of store.sessions) {
if (session.expiresAt < now) {
expiredIds.push(id);
if (session.expiresAt <= now) {
expiredIds.push(id)
}
}
for (const id of expiredIds) {
const session = store.sessions.get(id);
const session = store.sessions.get(id)
if (session) {
store.sessionTokens.delete(session.token);
store.sessions.delete(id);
store.sessionTokens.delete(session.token)
store.sessions.delete(id)
}
}
return { success: true, data: expiredIds.length };
return { success: true, data: expiredIds.length }
}