tdweb: drop localForage, increase cache limits

GitOrigin-RevId: efc9f7e95bf070cf802504453f10830acf6fa62c
This commit is contained in:
Arseny Smirnov 2019-07-25 18:27:03 +03:00
parent e07b03dea3
commit 3f138f4edc
2 changed files with 18 additions and 5 deletions

View File

@ -442,7 +442,7 @@ class FileManager {
init() { init() {
this.idb = new Promise((resolve, reject) => { 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.onsuccess = () => resolve(request.result);
request.onerror = () => reject(request.error); request.onerror = () => reject(request.error);
}); });
@ -490,10 +490,10 @@ class FileManager {
} }
if (file.arr) { if (file.arr) {
const now = Date.now(); const now = Date.now();
while (this.totalSize > 10000000) { while (this.totalSize > 100000000) {
const node = this.lru.getLru(); const node = this.lru.getLru();
// immunity for 5 seconds // immunity for 60 seconds
if (node.usedAt + 5 * 1000 > now) { if (node.usedAt + 60 * 1000 > now) {
break; break;
} }
const lru_info = this.cache.get(node.value); const lru_info = this.cache.get(node.value);
@ -545,7 +545,7 @@ class FileManager {
query.reject(); query.reject();
} }
}; };
request.onerror = query.reject; request.onerror = () => query.reject(request.error);
} }
} }

View File

@ -217,11 +217,15 @@ class InboundFileSystem {
const request = indexedDB.open(dbName); const request = indexedDB.open(dbName);
request.onsuccess = () => resolve(request.result); request.onsuccess = () => resolve(request.result);
request.onerror = () => reject(request.error); request.onerror = () => reject(request.error);
request.onupgradeneeded = () => {
request.result.createObjectStore('keyvaluepairs');
};
}); });
ifs.load_pids(); ifs.load_pids();
const FS = await FS_promise; const FS = await FS_promise;
await ifs.idb;
ifs.FS = FS; ifs.FS = FS;
ifs.FS.mkdir(root); ifs.FS.mkdir(root);
const create_time = (performance.now() - start) / 1000; const create_time = (performance.now() - start) / 1000;
@ -371,6 +375,15 @@ class InboundFileSystem {
try { try {
this.forget(pid); this.forget(pid);
//await this.store.removeItem(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) { } catch (e) {
log.error('Failed unlink ' + pid + ' ', e); log.error('Failed unlink ' + pid + ' ', e);
} }