perf: skip missing Matrix IDB snapshot locks

This commit is contained in:
Peter Steinberger
2026-04-17 16:24:29 +01:00
parent a954e2fb46
commit 5f3bb53788
3 changed files with 11 additions and 0 deletions

View File

@@ -91,6 +91,7 @@ describe("Matrix IndexedDB persistence lock ordering", () => {
});
await persistIdbToDisk({ snapshotPath, databasePrefix: "openclaw-matrix-test" });
fs.writeFileSync(snapshotPath, "[]", "utf8");
withFileLockMock.mockImplementationOnce(async (_filePath, options) => {
capturedOptions.push(options as CapturedLockOptions);
return false;

View File

@@ -93,6 +93,13 @@ describe("Matrix IndexedDB persistence", () => {
expect(dbs).toEqual([]);
});
it("returns false without warning when the snapshot does not exist yet", async () => {
const restored = await restoreIdbFromDisk(path.join(tmpDir, "missing-snapshot.json"));
expect(restored).toBe(false);
expect(warnSpy).not.toHaveBeenCalled();
});
it("serializes concurrent persist operations via file lock", async () => {
const snapshotPath = path.join(tmpDir, "concurrent-persist.json");
await seedDatabase({

View File

@@ -217,6 +217,9 @@ function resolveDefaultIdbSnapshotPath(): string {
export async function restoreIdbFromDisk(snapshotPath?: string): Promise<boolean> {
const candidatePaths = snapshotPath ? [snapshotPath] : [resolveDefaultIdbSnapshotPath()];
for (const resolvedPath of candidatePaths) {
if (!fs.existsSync(resolvedPath)) {
continue;
}
try {
const restored = await withFileLock(
resolvedPath,