Skip to content

Commit 1a59cc2

Browse files
committed
do not constantly refresh filecache
1 parent 6827865 commit 1a59cc2

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

viewer/src/main/IDBCache.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isEqual } from "lodash";
12
import { IndexedDBCacheEntry, IndexedDBCacheID, IndexedDBNoPerms, IndexedDBXTEAID } from "../common/CacheDirectory";
23
import { db } from "../common/db";
34

@@ -133,7 +134,15 @@ export async function refreshIDBEntry(key: number, file?: FileSystemHandle): Pro
133134
console.log(`removing entry ${file.name} because it has no cache`);
134135
deleteIDBEntry(key);
135136
} else {
136-
db.put("fileCache", e, key);
137+
let tx = db.transaction(["fileCache"], "readwrite");
138+
tx.done.catch(() => {}); // do not unhandledrejection for abort
139+
let store = tx.objectStore("fileCache");
140+
let prevVal = await store.get(key);
141+
if (isEqual(prevVal, e)) {
142+
tx.abort();
143+
} else {
144+
await store.put(e, key);
145+
}
137146
}
138147
return e;
139148
}

0 commit comments

Comments
 (0)