You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use fake-indexeddb for testing, which works great with Dexie except for problems with liveQuery's apparent* dependence on a global (*I may have misunderstood something!).
I believe it'll be fixed by being able to give liveQuery a reference to a specific indexedDb instance (like new Dexie can with DexieOptions).
How my FakeIndexedDb tests work
I create a new FakeIndexedDb instance per test, and pass it to Dexie.
import { IDBFactory, IDBKeyRange } from "fake-indexeddb";
const _indexedDB = new IDBFactory();
const db = new Dexie('name', {indexedDB: _indexedDB, IDBKeyRange})
I then use live query as normal on db.
What goes wrong
As I add more tests, FakeIndexedDb/Dexie run slower and slower. E.g. several seconds to run 'toArray' on an empty table - but that same test runs in 400ms when run in isolation.
To prove it's some kind of leak somewhere:
I'm forced to use import "fake-indexeddb/auto" at the top of the test file, or liveQuery won't work. This is FakeIndexedDb's global. Only liveQuery needs it, as Dexie itself it passed an individual FakeIndexedDb instance. I suspect that global is being marshalled across tests by the test runner, causing the slow down.
If I split the tests across separate test files, the Dexie/IDB performance is fine.
Request
I want to pass liveQuery something equivalent to DexieOptions, to give it the FakeIndexedDb instance.
I'd happily make a fork/PR myself, but some pointers of where to start from in ./src/live-query would help enormously (I've not succeeded at even finding any reference to the global indexedDb so far).
The text was updated successfully, but these errors were encountered:
liveQuery() is not dependant on the indexedDB being present on the global object actually. It depends on globalEvents which is basically an event set with one single event "x-storagemutated-1". This static variable is part of the "dexie" module so it's also not dependant on anything on the global object. Not sure why it slows down though.
The liveQuery will find the indexedDB implementation anyway because the actual queriers will always use a db instance to do the query. liveQuery can monitory queries from different databases in a single observable as long as all of them are dexie's but they can actually use different indexedDB implementations under the hood.
Goal
I use fake-indexeddb for testing, which works great with Dexie except for problems with liveQuery's apparent* dependence on a global (*I may have misunderstood something!).
I believe it'll be fixed by being able to give liveQuery a reference to a specific indexedDb instance (like
new Dexie
can with DexieOptions).How my FakeIndexedDb tests work
I create a new FakeIndexedDb instance per test, and pass it to Dexie.
I then use live query as normal on
db
.What goes wrong
As I add more tests, FakeIndexedDb/Dexie run slower and slower. E.g. several seconds to run 'toArray' on an empty table - but that same test runs in 400ms when run in isolation.
To prove it's some kind of leak somewhere:
import "fake-indexeddb/auto"
at the top of the test file, or liveQuery won't work. This is FakeIndexedDb's global. Only liveQuery needs it, as Dexie itself it passed an individual FakeIndexedDb instance. I suspect that global is being marshalled across tests by the test runner, causing the slow down.Request
I want to pass liveQuery something equivalent to
DexieOptions
, to give it the FakeIndexedDb instance.I'd happily make a fork/PR myself, but some pointers of where to start from in ./src/live-query would help enormously (I've not succeeded at even finding any reference to the global indexedDb so far).
The text was updated successfully, but these errors were encountered: