Files
Tom MoorandClaude Fable 5.1 b2a1e10e48 Batch large table deletes in teamPermanentDeleter (#13610)
* fix: batch large deletes in teamPermanentDeleter to shorten lock time

Delete events, collections, and documents in batches of ids outside the
final transaction so row locks are held briefly instead of for the whole
team deletion, which blocked the hourly old-events cleanup for hours.

* fix: type batched destroy helper structurally

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* fix: guard whole team deletion with a non-blocking mutex

Move the concurrency guard from the final transaction to the whole
routine so a second worker skips before running the batched deletes.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-02 06:12:12 -04:00

54 lines
1.1 KiB
TypeScript

import { vi } from "vitest";
export class MutexLock {
// Default expiry time for acquiring lock in milliseconds
public static defaultLockTimeout = 4000;
/**
* Acquires a mock lock.
*/
public static acquire = vi.fn().mockResolvedValue({
release: vi.fn().mockResolvedValue(true),
expiration: Date.now() + 10000,
});
/**
* Runs the routine without a lock.
*/
public static using = vi.fn(
(
_resource: string,
_timeout: number,
routine: (signal: never) => unknown
) => routine(undefined as never)
);
/**
* Runs the routine without a lock.
*/
public static tryUsing = vi.fn(
(
_resource: string,
_timeout: number,
routine: (signal: never) => unknown
) => routine(undefined as never)
);
/**
* Releases a mock lock.
*/
public static release = vi.fn().mockResolvedValue(true);
/**
* Returns the mock redlock instance
*/
public static get lock() {
return {
acquire: vi.fn().mockResolvedValue({
release: vi.fn().mockResolvedValue(true),
expiration: Date.now() + 10000,
}),
};
}
}