mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-30 16:54:57 +00:00
code: expired,dbal,clean (1 files)
This commit is contained in:
@@ -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 }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user