使用indexedDB遇写入延迟问题:安装扩展后卡顿求助
IndexedDB安装其他扩展后出现严重写入延迟问题
在使用IndexedDB时遇到异常:每当安装其他扩展程序后,IndexedDB有时会出现严重的数据写入延迟。尝试过直接使用IndexedDB API以及基于IndexedDB的库,均无法解决该问题。
以下是使用的代码:
function updateRecord({ sessionId, ...record }) { return new Promise(async(resolve, reject) => { try { console.log( '%c Inside update record ', 'background: #222; color: #bada55' ); const dbPromise = await idb.openDB('testbuddyExtension', 1, { upgrade(db) { const store = db.createObjectStore('testbuddy', { keyPath: 'sessionId', }); store.createIndex('keyIndex', 'tabId'); }, }); const existingRecord = await dbPromise.get('testbuddy', sessionId); const updatedPayload = { ...record, ...(existingRecord ? existingRecord : {}), }; await dbPromise.put('testbuddy', { ...updatedPayload, sessionId }); console.log( '%c Everything is now done! ', 'background: #222; color: #bada55' ); resolve(true); } catch (error) { console.log('%c Error found! ', 'background: #222; color: #bada55'); console.log({ error }); reject(false); } }); }
需要说明的是,该延迟并非因一次性写入大量数据导致,我曾用同一脚本一次性写入过数兆字节的数据,未出现此类问题。
内容的提问来源于stack exchange,提问作者Joy Gupta
相关产品推荐
相关产品推荐

