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
When integrating the caches and optimistic updates into our codes, we now need to load & sort one entire table, and don't know which implementation is more efficient. So, could you please give any advices on this?
Background:
the records defined with a primary key of id, which is a simple string uuid,
the number of the records is up to about thousands, at most tens of thousands,
Objective: load all the records in a particular table, and sort the loaded by id in ascending.
The code snippet is as below.
// #1. load & sort with `Table.orderBy()`liveQuery(()=>db.table1.orderBy('id').toArray());// #2. load the records, and sort separatelyliveQuery(()=>db.table1.toArray()).subscribe(records=>records.sort((r1,r2)=>r1.id===r2.id ? 0 : (r1.id<r2.id) ? -1 : 1));
Our current codes are implemented as the second, since we think it would release the underlying transaction sooner. However,
is our consideration meaningful, even without caches and optimistic updates? The best way should do a performance test, and we will do it later. Could you please give any analysis or suggestions?
With the caches now, we guest the first implementation might outperform for loading, as well as for reloading after CRUDs, since the records are already sorted by PK and cached. Is our guess meaningful or correct, from your opinion?
Thanks!
The text was updated successfully, but these errors were encountered:
db.table1.toArray() will always return a result sorted by the primary key. Basically, it's the same as doing db.table1.orderBy('id').toArray() - so the first one isn't optimized more than the second one. And when using caches and optimistic updates (the default in latest dexie@4), this contract remains the same.
So my advice is to keep doing the orderBy() query (or just a toArray()) and skip the manual sorting part.
When integrating the caches and optimistic updates into our codes, we now need to load & sort one entire table, and don't know which implementation is more efficient. So, could you please give any advices on this?
Background:
id
, which is a simple string uuid,Objective: load all the records in a particular table, and sort the loaded by
id
in ascending.The code snippet is as below.
Our current codes are implemented as the second, since we think it would release the underlying transaction sooner. However,
Thanks!
The text was updated successfully, but these errors were encountered: