1
votes

The first time using the index query takes too long.

usage scenarios: mobile use webview.

After the data is saved into indexedDb, the first time you open the page query is extremely slow.

query code:

var startTime = new Date().getTime();
var request = indexedDB.open("yfg");
request.onerror = function(event) {
	alert("Why didn't you allow my web app to use IndexedDB?!");
};
request.onsuccess = function(event) {
	var table = [];
	var db = request.result;
	var objectStore = db.transaction("table").objectStore("table");

	//objectStore.openCursor().onsuccess = function(event) {
	objectStore.openCursor(null,IDBCursor.NEXT).onsuccess = function(event) {
		var cursor = event.target.result;
		if (cursor) {
			table.push(cursor.value);
			cursor.continue();
		}else {
			//alert("No more entries!");
			console.log(table);
			var endTime = new Date().getTime();
			console.log("总耗时:",(endTime-startTime)/1000);
		}
	};
};

Execute on console:

The first result: enter image description here

The second result: enter image description here

Browser version: enter image description here

The specific content of each piece of data: enter image description here

This table sheet has these data: enter image description here

1
how much data is being transferred? - Jaromanda X
Table sheet more than 1200 bars - fan
bars? is that a new unit of measuring data? how many bytes in a bar? nevermind, just re-read the question properly and realise you're using IndexedDB - Jaromanda X
My English is bad. Table sheet more than 1200 data. - fan
I reorganized the question - fan

1 Answers

0
votes

Try using IDBObjectStore.prototype.getAll. getAll generates an array, similar to what you are doing, but involves fewer function calls than openCursor and is therefore more performant.

However, unlike openCursor, getAll may not be supported because it is a newer feature of indexedDB. The linked page shows a compatibility table but that may also be out of date.