fix: deduplicate joins keys when syncMode: 'on-demand' #995
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.
When collections with syncMode: 'on-demand' are joined, the where clause sent to the server via loadSubset often can contain duplicate values in the 'in' condition. This occurs when the active side of the join has multiple rows with the same join key (e.g., multiple posts by the same user).
Before: userId IN (1, 1, 1, 2, 2)
After: userId IN (1, 2)
I discovered this when developing a pocketbase adapter where it was crumbling under requests like:
I also see that DB isn't de-duplicating requests like:
Will also send the where with duplicated values to the collection. To me that's acceptable though because it's what the caller requested, but I can add deduplication to it if you'd like.
Or maybe this PR is off-base and the collection adapter should be handling this? I did add deduplication to my library but I did find it surprising and others may as well.
🎯 Changes
✅ Checklist
☝️ this link is broken db doesn't seem to have a CONTRIBUTING.md at all
pnpm test:pr.☝️ there is not a package.json script for
test:pr, but I have ran withpnpm test🚀 Release Impact
I did not add a changelog because I'd consider this a simple bug fix not worth noting. happy to do so if you'd like