Files
esign/packages/lib/jobs/definitions/internal/cleanup-rate-limits.handler.ts
zeekayandHanzo Dev b54e5cef23 fix(lint): drop assignments nothing reads
ESLint 10's recommended set added no-useless-assignment, which fails on a
value no later statement can read. Fourteen places had one:

- An initial value every path overwrites before reading: `let x = null`
  ahead of a try that assigns it or leaves, the webhook response body both
  branches set, the rate-limit loop's counter, the avatar's previous id and
  the license response. They are declared without one; TypeScript still
  checks each is assigned before use.
- Konva stages and layers set to null after destroy(), just before the
  function returns and the variable goes out of scope. The nulls go, and
  the variables are const.
- Two in the v1 PDF field writer: textFieldBoxY recomputed after the only
  read of it had already been copied into adjustedFieldY, and a line reset
  to '' that both following branches overwrite.
- The folder breadcrumbs' currentFolderId, reassigned in a loop that walks
  by currentFolder.parentId; the first query reads folderId directly.

No output changes: each removed value was provably never read.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-19 05:04:46 -07:00

38 lines
1.1 KiB
TypeScript

import { DateTime } from 'luxon';
import { prisma } from '@hanzo/esign-prisma';
import type { JobRunIO } from '../../client/_internal/job';
import type { TCleanupRateLimitsJobDefinition } from './cleanup-rate-limits';
const BATCH_SIZE = 10_000;
export const run = async ({ io }: { payload: TCleanupRateLimitsJobDefinition; io: JobRunIO }) => {
const cutoff = DateTime.now().minus({ hours: 24 }).toJSDate();
let totalDeleted = 0;
let deleted: number;
do {
// Prisma doesn't support DELETE with LIMIT, so use raw SQL for batching
// to avoid long-running transactions that could lock the table. `rowid` is
// SQLite's row identity — the store this schema targets.
deleted = await prisma.$executeRaw`
DELETE FROM "RateLimit"
WHERE rowid IN (
SELECT rowid FROM "RateLimit"
WHERE "createdAt" < ${cutoff}
LIMIT ${BATCH_SIZE}
)
`;
totalDeleted += deleted;
} while (deleted >= BATCH_SIZE);
if (totalDeleted > 0) {
io.logger.info(`Cleaned up ${totalDeleted} expired rate limit entries`);
} else {
io.logger.info('No expired rate limit entries to clean up');
}
};