mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:50:43 +00:00
perf: skip missing Matrix IDB snapshot locks
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user