Avoid optimistic updates for explicit readwrite transactions #1881
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Never let an 'rw' transaction leak information to live queries before the transaction commits. Even if liveQueries could benefit from optimistic updates, never let them through if they origin from an explicit 'rw' transaction. Instead let the liveQuery update when the 'rw' transaction commits. Still allow optimistic updates from "transactionless" operations such as
db.friends.update({name: 'Bar'})
without a transaction block around.In normal situations, there's no much benefit from optimistic updates with IndexedDB since the transactions are fast and local anyway. However, in case a long-running transaction is locking the database, and you are showing an editable field component, it can be nice that the user updates are immediately propagated to the view no matter whether a transaction is locking a table. Notice that in case the optimistic update finally fails when its transaction commits (all operations have implicit transactions in backround), the optimistic update will be reverted.
We could also just skip the whole optimistic feature in its whole and only take the benefits we have with the cache. But for 2 reasons, I want to keep it.
First for the sake of immediate view updates from simple update / put / add / delete operations.
Second because we need to computations anyway if we want to optimize paged offset/limit queries in future.