tdweb: drop localForage, increase cache limits
GitOrigin-RevId: efc9f7e95bf070cf802504453f10830acf6fa62c
This commit is contained in:
parent
e07b03dea3
commit
3f138f4edc
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user