-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
Live QueryLive query subscription featureLive query subscription feature
Description
Summary
Implement client-side sorting mechanism to prevent unnecessary server refetches when entities are updated in live query subscriptions.
Background
When using watch() subscriptions without limit or skip clauses, the client can optimize updates by:
- Updating the modified entity in the local list
- Re-sorting the list client-side
This avoids the "sliding window" problem and reduces server load.
Proposed Implementation
When a snapshot update is received:
- If the subscription has no
limit/skipoptions:- For
modified: Update the entity in place and re-sort - For
added: Insert the entity and re-sort - For
removed: Remove the entity from the list
- For
- If the subscription has
limit/skip:- Request a full refetch from the server (sliding window case)
Technical Details
Sort Parsing
The SDK already uses -- prefix for descending sort (e.g., --price for descending by price). Implement a sort comparator that:
- Parses the sort string
- Handles ascending/descending
- Supports nested field paths
Files to modify:
src/modules/entities.ts- Add sorting logic in watch handlersrc/utils/common.ts- Add sort utility function
Considerations
- Document that
limit/skipsubscriptions will trigger full refetches - Consider recommending filter-only subscriptions in docs
- Maintain consistency with server-side sort behavior
Related
- Depends on Implement
watch()method for live query subscriptions #83 (watch() method implementation)
Metadata
Metadata
Assignees
Labels
Live QueryLive query subscription featureLive query subscription feature