Optimized Bulk (Chunk) Upload Of Objects Into IndexedDB

后端 未结 2 1500
有刺的猬
有刺的猬 2020-12-20 18:47

I want to add objects into some table in IndexedDB in one transaction:

_that.bulkSet = function(data, key) {
    var transaction = _db.transaction([_tblName]         


        
2条回答
  •  死守一世寂寞
    2020-12-20 19:31

    IndexedDB is actually designed to optimize for bulk operations. The problem is that the spec and certain docs does not advertice the way it works. If paying certain attention to the parts in the IndexedDB specification that defines how all the mutating operations in IDBObjectStore works (add(), put(), delete()), you'll find out that it allow callers to call them synchronously and omit listening to the success events but the last one. By omitting doing that (but still listen to onerror), you will get enormous performance gains.

    This example using Dexie.js shows the possible bulk speed as it inserts 10,000 rows in 680 ms on my macbook pro (using Opera/Chromium).

    Accomplished by the Table.bulkPut() method in the Dexie.js library:

    db.objects.bulkPut(arrayOfObjects)
    

提交回复
热议问题