`title: IndexedDB 批量导入与事务分块策略``categories: Web 开发/前端/数据管理``keywords: IndexedDB,批量导入,事务,分块,吞吐``description: 在大规模数据导入场景下采用事务分块与并行批次策略,提升吞吐并避免长事务失败与配额压力。`分块与批次每批次固定条数(如 1000)进入单事务;批次间短暂停顿以释放事件循环。示例async function bulkImport(db, items, chunk = 1000) { for (let i = 0; i < items.length; i += chunk) { await new Promise((resolve, reject) => { const tx = db.transaction('items', 'readwrite'); const s = tx.objectStore('items'); for (const it of items.slice(i, i + chunk)) s.put(it); tx.oncomplete = () => resolve(); tx.onerror = () => reject(tx.error); }); await new Promise(r => setTimeout(r)); } }

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部
1.813478s