IndexedDB 存储大量数据时页面卡顿怎么办?
我在用 IndexedDB 缓存用户的历史操作记录,数据量大概有几万条,每次打开页面读取数据时都会明显卡顿好几秒。
试过用 cursor 分批读取,但还是卡。有没有更高效的读取方式?或者是不是我建索引的方式有问题?
这是我的读取代码:
const transaction = db.transaction(['logs'], 'readonly');
const store = transaction.objectStore('logs');
const allLogs = [];
store.openCursor().onsuccess = (event) => {
const cursor = event.target.result;
if (cursor) {
allLogs.push(cursor.value);
cursor.continue();
} else {
// 处理 allLogs
renderLogs(allLogs);
}
};
暂无解答