Repository navigation
fix: CardDAV: sync-collection with a limit loses changes - #1682
Open
mstilkerich wants to merge 1 commit into
Open
mstilkerich wants to merge 1 commit into
mstilkerich wants to merge 1 commit into
Conversation
…ng changes getChangesForAddressBook() applied the client's DAV:limit to the changes query, but always returned the address book's current sync-token and never flagged the result as truncated. A client requesting e.g. nresults=1 with several pending changes received at most one change together with the latest token, so all remaining changes were silently skipped. Fetch one row more than the limit to detect truncation, as the CalDAV backend does. If there are more changes, set result_truncated and return the synctoken of the first change that is not reported, so the client continues from there on its next request.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1682 +/- ##
============================================
+ Coverage 97.22% 97.23% +0.01%
- Complexity 2845 2847 +2
============================================
Files 175 175
Lines 8887 8893 +6
============================================
+ Hits 8640 8647 +7
+ Misses 247 246 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
CardDAV: sync-collection with a limit loses changes
Problem
When a client sends a
sync-collectionREPORT with a previous sync-token and aDAV:limit,Sabre\CardDAV\Backend\PDO::getChangesForAddressBook()adds aLIMITto the changes query, but:result_truncated, so no507response is added for the collection.The client therefore gets at most
limitchanges plus the latest token, and believes it is fully up to date. The remaining changes are never reported. Withnresults=1and several pending deletes, the client keeps the deleted contacts.The CalDAV backend already handles this case.
Fix
This follows the approach in
Sabre\CalDAV\Backend\PDO::getChangesForCalendar():limit + 1change rows to detect truncation.result_truncatedand return a sync-token that only covers the reported changes.Different from the CalDAV backend, the code counts change rows for the limit, not merged results. In case of multiple changes to the same object, it will return fewer results than allows by the limit parameter, but will still be able to report result truncation correctly (which is required by RFC 6578).
Tests
New tests in
tests/Sabre/CardDAV/Backend/AbstractPDOTestCase.php:testGetChangesWithLimit: three deletes paged withlimit=1. Each page reports one delete and is truncated, and the final page returns the current token without truncation.testGetChangesWithLimitAndDuplicates: two changes to the same card merge into one result on a truncated page, followed by the remaining change.Both tests fail without the fix. The existing
testGetChangesis unchanged and passes.Other noticed issue (not fixed)
Both CalDAV and CardDAV ignore the limit parameter when no sync-token is given (initial sync). However, this is not conform with RFC 6578. Contrary to the docblock comment above
getChangesForAddressBook(), the limit is not suggestive, and the server is not free to ignore it. The server has two conforming options:DAV:number-of-matches-within-limitspostcondition.