I stored some jpeg files (exactly 350, same files same size. Total: 336.14 MB) as Blob
in IndexedDB. It took around 1 second to complete the transaction. Then I read all the data to an array and again sored to IndexedDB. But this time it takes around 15 Seconds. I observed this as a consistent behavior. Anything wrong here? I used performance.now()
to get the time difference
Files: 350, Size of each: 937 KB, Browser: Chrome and Chromium Edge
//Open var dbOpen = indexedDB.open(INDEXED_DB_NAME, INDEXED_DB_VERSION); dbOpen.onupgradeneeded = function (e) { console.log("onupgradeneeded"); var store = e.currentTarget.result.createObjectStore( IMAGE_DATA_STORE, { autoIncrement: true }); }; dbOpen.onsuccess = function (e) { image_data_db = dbOpen.result; console.log("indexed DB opened"); }; //Initial Write var inputFiles = document.getElementById('inputFiles'); for (var i = 0; i < inputFiles.files.length; i++) { let file = inputFiles.files[i]; var b = new Blob([file], { type: file.type }); fileblobs.push(b); } StoreIdb(fileblobs); // < First write //StoreIdb() var trx = image_data_db.transaction(IMAGE_DATA_STORE, 'readwrite'); var imagestore = trx.objectStore(IMAGE_DATA_STORE); for (i = 0; i < fileblobs.length; i++) { request = imagestore.add(fileblobs[i]); request.onsuccess = function (e) { console.log('added'); }; request.onerror = function (e) { console.error("Request Error", this.error); }; } trx.onabort = function (e) { console.error("Exception:", this.error, this.error.name); }; trx.oncomplete = function (e) { console.log('completed'); } //Read var objectStore = image_data_db.transaction(IMAGE_DATA_STORE).objectStore(IMAGE_DATA_STORE); objectStore.openCursor().onsuccess = function (e) { var cursor = e.target.result; if (cursor) { blobArray.push(cursor.value.blob); cursor.continue(); } else { // completed } } // blobArray will be used for second time << Second Write
https://stackoverflow.com/questions/66864271/writing-same-data-in-indexeddb-first-time-and-second-time-takes-much-difference March 30, 2021 at 11:06AM
没有评论:
发表评论