diff --git a/example/web/tdweb/src/index.js b/example/web/tdweb/src/index.js index fc50a6caf..9d044a368 100644 --- a/example/web/tdweb/src/index.js +++ b/example/web/tdweb/src/index.js @@ -442,7 +442,7 @@ class FileManager { init() { this.idb = new Promise((resolve, reject) => { - const request = window.indexedDB.open(this.instanceName); + const request = window.indexedDB.open(this.instanceName, 1); request.onsuccess = () => resolve(request.result); request.onerror = () => reject(request.error); }); @@ -490,10 +490,10 @@ class FileManager { } if (file.arr) { const now = Date.now(); - while (this.totalSize > 10000000) { + while (this.totalSize > 100000000) { const node = this.lru.getLru(); - // immunity for 5 seconds - if (node.usedAt + 5 * 1000 > now) { + // immunity for 60 seconds + if (node.usedAt + 60 * 1000 > now) { break; } const lru_info = this.cache.get(node.value); @@ -545,7 +545,7 @@ class FileManager { query.reject(); } }; - request.onerror = query.reject; + request.onerror = () => query.reject(request.error); } } diff --git a/example/web/tdweb/src/worker.js b/example/web/tdweb/src/worker.js index da95ead62..03700e4f6 100644 --- a/example/web/tdweb/src/worker.js +++ b/example/web/tdweb/src/worker.js @@ -217,11 +217,15 @@ class InboundFileSystem { const request = indexedDB.open(dbName); request.onsuccess = () => resolve(request.result); request.onerror = () => reject(request.error); + request.onupgradeneeded = () => { + request.result.createObjectStore('keyvaluepairs'); + }; }); ifs.load_pids(); const FS = await FS_promise; + await ifs.idb; ifs.FS = FS; ifs.FS.mkdir(root); const create_time = (performance.now() - start) / 1000; @@ -371,6 +375,15 @@ class InboundFileSystem { try { this.forget(pid); //await this.store.removeItem(pid); + let idb = await this.idb; + await new Promise((resolve, reject) => { + let write = idb + .transaction(['keyvaluepairs'], 'readwrite') + .objectStore('keyvaluepairs'); + const request = write.delete(pid); + request.onsuccess = () => resolve(request.result); + request.onerror = () => reject(request.error); + }); } catch (e) { log.error('Failed unlink ' + pid + ' ', e); }