-
Notifications
You must be signed in to change notification settings - Fork 46
[WIP] Incremental Watched Queries #614
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 8a42cda The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@@ -14,4 +14,4 @@ import { usePowerSyncStatus } from './usePowerSyncStatus'; | |||
* </div> | |||
* }; | |||
*/ | |||
export const useStatus = usePowerSyncStatus; | |||
export const useStatus = () => usePowerSyncStatus(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes an issue where the docs state the useStatus
is deprecated due to usePowerSyncStatus
being deprecated.
Overview
Our current Watched query implementations emit results whenever a change to a dependant SQLite table occurs. The table changes might not affect the query result set, but we still query and emit a new result set for each table change. The result sets typically contain the same data, but these results are new Array/object references which will cause re-renders in certain frameworks like React.
This PR overhauls, improves and extends upon the existing watched query implementations by introducing incremental watched queries.
The first version of incremental watched queries operates on the principle of comparing result sets. Internally we still query on each dependant table change, but we compare the previous and new result sets - only emitting values if there is a change.
Implementation
The logic required for incrementally watched queries requires additional computation and introduces additional complexity to the implementation. For these reasons a new concept of a
WatchedQuery
class is introduced, along with a newincrementalWatch
method allows building an instance ofWatchedQuery
.Note: APIs here are still a work in progress.
The
assetsQuery
is smart, it:updateSchema
WatchedQuery
instances retain the latest state in memory. SharingWatchedQuery
instances can be used to introduce caching and reduce the number of duplicate DB queries between components.The incremental logic is customisable. Comparison based queries can specify custom logic for performing comparisons on the relevant data set. By default a
JSON.stringify
approach is used. Different data sets might have more optimal implementations.Updates to query parameters can be performed in a single place, affecting all subscribers.
Reactivity
The existing
watch
method and Reactivity packages have been updated to use incremental queries with comparison defined as an opt-in feature (defaults to no changes).New hooks have also been added to use shared
WatchedQuery
instances.Still to Come
The comparison processor is just one method for performing incremental queries. SQLite trigger based methods will also be introduced shortly.