Bucket Parameters Lookup Fix #165
Merged
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.
Overview
For reference see Discord thread.
The resolved sync buckets would be missing entries which matched data after updating (moving) relational linked columns.
Root Cause
The
getParameterSetsmethod was not returning the correct parameter sets after updating atodo_list'slist_idcolumn. The query fetched allbucket_parametersthat:list_ids),_idvalues smaller than the currentcheckpoint, andgroup_id(sync rules set).The issue arose during the
$groupstage, where results were grouped by thekeyfield alone. Since thekeywas not unique for different lookup values, updates introducing REMOVE entries with emptybucket_parameterscould override valid entries, leading to incorrect results.Steps to Reproduce
See the screenshot of the
bucket_parameterscollection in MongoDB before and after executing anUPDATE todos set list_id = 2 where id = 12.Initial State:
Todo
id=12belongs to listid=10with its correspondinglookupandbucket_parameters.Todo
id=11belongs to listid=2.The
bucket_parametersentries match the input lookups for:list_id=10=>todo_id=12andlist_id=2=>todo_id=11Update:
Update Todo
id=12to belong to listid=2..This creates a
bucket_parametersentry which now associateslist_id=2=>todo_id=12and aREMOVEbucket_parametersentry which removes the association oflist_id=10(lookup) totodo_id=12. The REMOVE entry is created after the new association.Issue:
When grouping results by key, the REMOVE entry (with empty bucket_parameters) overrides valid entries with the same key but a different lookup (e.g., for list 2).
Refer to the attached screenshot for a clear visual of the issue:
Before the update: the relevant lookups for each todo item are valid.
After the update: A REMOVE operation appears, the grouping in the
getParameterSetsquery will return thebucket_parametersfor the last entry which is the empty array from the remove entry.Solution
The
$groupstage was updated to use a composite_idobject:This ensures that each unique combination of
keyandlookupis preserved in the grouped results, preventing REMOVE entries from overriding valid data.Verification
Tested the fix by reproducing the issue as described above.
After applying the fix, the query correctly groups results by both key and lookup, preserving the valid bucket_parameters for each combination.