Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid optimistic updates for explicit readwrite transactions #1881

Merged
merged 8 commits into from
Feb 7, 2024

Conversation

dfahlander
Copy link
Collaborator

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.

@dfahlander dfahlander marked this pull request as ready for review February 7, 2024 20:44
@dfahlander dfahlander merged commit 1eacbc8 into master Feb 7, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant