mirror of
https://github.com/outline/outline.git
synced 2026-11-24 23:00:18 +03:00
* 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>
54 lines
1.1 KiB
TypeScript
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,
|
|
}),
|
|
};
|
|
}
|
|
}
|