==========
update:
maybe this is not query make the indexeddb slow, but the save operation blocking the db. I get the data from webSocket, so almost 900 items need to save per second, and I save it one by one. Now I save it at memory, use "bulkPut" function save all, almost 13 seconds done.
Apologize for my incomplete description, and thanks for all help!
==========
I try indexeddb first, but two nested transaction make the inner one very slow. Then I use Dexie.js, but things are same.
I refer to document,they says nested query are allowed, but all the example are single query.
In my case, there are two stores, one is named 'ps', and the other is named 'socket'. 'ps' objectStore has 4 items, but socket objectStore has maybe 10,000 items.
db.ps.toArray().then(lines => {
lines.map(l => {
console.log(l);
console.time(l.name + '_' + 'sockets');
db.socket.where('ps').equals(l.name).toArray().then(sockets => {
console.timeEnd(l.name + '_' + 'sockets');
})
})
})
and here are the time log results:
67_sockets: 131583.873046875ms
42_sockets: 131614.40478515625ms
33_sockets: 131631.00805664062ms
22_sockets: 131634.97705078125ms
so where is the problem? I think indexeddb is not so slow.
Encapsulate the whole function in a transaction block, otherwise each operation will launch in it's own transaction, which could show down the query.
let promise=db.transaction('r', db.ps, db.socket, ()=>
db.ps.toArray().then(lines => {
return lines.map(l => {
console.time(l.name + '_' + 'sockets');
return db.socket.where('ps').equals(l.name).toArray().then(sockets => {
console.timeEnd(l.name + '_' + 'sockets');
return sockets;
})
})
}));
If still slow, check how large objects you are storing in the 'socket' object store. Or could it be a few of them containing huge amount of data?