`title: IndexedDB 在 Web Worker 中的事务调度与吞吐优化``categories: Web 开发/前端/数据管理``keywords: IndexedDB,Web Worker,事务,并发,吞吐``description: 在 Web Worker 中调度 IndexedDB 读写,利用事务聚合与批处理提升吞吐并避免主线程阻塞。`Worker 调度self.onmessage = async (e) => {
const { type, items } = e.data;
if (type === 'bulkPut') {
const db = await openDB('worker-db', 1);
await bulkPut(db, items);
postMessage({ ok: true });
}
};
事务聚合将大量写操作合并到单事务内,必要时分批(如每 1000 条)。

发表评论 取消回复