mirror of
https://github.com/documenso/documenso.git
synced 2026-08-26 00:02:43 +10:00
feat: add qr signatures
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { prisma } from '@documenso/prisma';
|
||||
|
||||
import type { JobRunIO } from '../../client/_internal/job';
|
||||
import type { TCleanupAnonymousTokensJobDefinition } from './cleanup-anonymous-tokens';
|
||||
|
||||
const BATCH_SIZE = 10_000;
|
||||
|
||||
export const run = async ({ io }: { payload: TCleanupAnonymousTokensJobDefinition; io: JobRunIO }) => {
|
||||
// Snapshot the cutoff so the run is bounded by the rows that were already
|
||||
// expired when it started, rather than chasing rows expiring mid-run.
|
||||
const cutoff = new Date();
|
||||
|
||||
let totalDeleted = 0;
|
||||
let deleted = 0;
|
||||
|
||||
do {
|
||||
// Postgres doesn't support DELETE with LIMIT, so batch via ctid to avoid
|
||||
// long-running transactions that could lock the table.
|
||||
deleted = await prisma.$executeRaw`
|
||||
DELETE FROM "AnonymousVerificationToken"
|
||||
WHERE ctid IN (
|
||||
SELECT ctid FROM "AnonymousVerificationToken"
|
||||
WHERE "expiresAt" < ${cutoff}
|
||||
LIMIT ${BATCH_SIZE}
|
||||
)
|
||||
`;
|
||||
|
||||
totalDeleted += deleted;
|
||||
} while (deleted >= BATCH_SIZE);
|
||||
|
||||
if (totalDeleted > 0) {
|
||||
io.logger.info(`Cleaned up ${totalDeleted} expired anonymous verification tokens`);
|
||||
} else {
|
||||
io.logger.info('No expired anonymous verification tokens to clean up');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
import type { JobDefinition } from '../../client/_internal/job';
|
||||
|
||||
const CLEANUP_ANONYMOUS_TOKENS_JOB_DEFINITION_ID = 'internal.cleanup-anonymous-tokens';
|
||||
|
||||
const CLEANUP_ANONYMOUS_TOKENS_JOB_DEFINITION_SCHEMA = z.object({});
|
||||
|
||||
export type TCleanupAnonymousTokensJobDefinition = z.infer<typeof CLEANUP_ANONYMOUS_TOKENS_JOB_DEFINITION_SCHEMA>;
|
||||
|
||||
export const CLEANUP_ANONYMOUS_TOKENS_JOB_DEFINITION = {
|
||||
id: CLEANUP_ANONYMOUS_TOKENS_JOB_DEFINITION_ID,
|
||||
name: 'Cleanup Anonymous Verification Tokens',
|
||||
version: '1.0.0',
|
||||
trigger: {
|
||||
name: CLEANUP_ANONYMOUS_TOKENS_JOB_DEFINITION_ID,
|
||||
schema: CLEANUP_ANONYMOUS_TOKENS_JOB_DEFINITION_SCHEMA,
|
||||
cron: '0 */2 * * *', // Every 2 hours.
|
||||
},
|
||||
handler: async ({ payload, io }) => {
|
||||
const handler = await import('./cleanup-anonymous-tokens.handler');
|
||||
|
||||
await handler.run({ payload, io });
|
||||
},
|
||||
} as const satisfies JobDefinition<
|
||||
typeof CLEANUP_ANONYMOUS_TOKENS_JOB_DEFINITION_ID,
|
||||
TCleanupAnonymousTokensJobDefinition
|
||||
>;
|
||||
Reference in New Issue
Block a user