Implement mitigation for server returning empty pages#90
Merged
Conversation
…o items Is legitimate possibility Signed-off-by: Claudio Cambra <developer@claudiocambra.com>
Server may return new page data when there are, in fact, no more pages to read Signed-off-by: Claudio Cambra <developer@claudiocambra.com>
Signed-off-by: Claudio Cambra <developer@claudiocambra.com>
Signed-off-by: Claudio Cambra <developer@claudiocambra.com>
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds logic to stop enumeration when a server erroneously returns a next‐page token despite all items already being delivered. It includes:
- A new test
testWorkingSetEnumerationStopsOnExhaustedTotalto verify the paginator halts on empty pages. - A
forceNextPageOnLastContentPageflag inMockRemoteInterfaceto simulate faulty servers. - Updates in
EnumeratorPageResponse,Enumerator, and the sync‐engine extension to track and applytotalcounts for terminating phantom pages.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| Tests/NextcloudFileProviderKitTests/EnumeratorTests.swift | Added a test verifying pagination stops when the total count is reached despite a phantom next‐page token |
| Tests/Interface/MockRemoteInterface.swift | Introduced forceNextPageOnLastContentPage to simulate servers that return empty pages |
| Sources/NextcloudFileProviderKit/Enumeration/EnumeratorPageResponse.swift | Changed total from let to var to allow updating the remaining item count on phantom pages |
| Sources/NextcloudFileProviderKit/Enumeration/Enumerator.swift | Added pageTotal tracking and logic to clear nextPage when index * pageItemCount >= total |
| Sources/NextcloudFileProviderKit/Enumeration/Enumerator+SyncEngine.swift | Modified the return for over‐indexed paginated requests to yield an empty metadata array instead of error |
Comments suppressed due to low confidence (2)
Sources/NextcloudFileProviderKit/Enumeration/EnumeratorPageResponse.swift:17
- [nitpick] Update this comment to note that
totalmay be mutated on subsequent pages (e.g., phantom pages) to control when pagination should end.
var total: Int? // Total item count, provided in the first non-offset paginated response
Tests/NextcloudFileProviderKitTests/EnumeratorTests.swift:585
- [nitpick] The debugPrint of the database isn’t needed for this test and may clutter logs; consider removing it.
debugPrint(db)
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #90 +/- ##
==========================================
+ Coverage 83.96% 84.00% +0.04%
==========================================
Files 70 70
Lines 15749 15852 +103
==========================================
+ Hits 13223 13317 +94
- Misses 2526 2535 +9 ☔ View full report in Codecov by Sentry. 🚀 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.
The server can return page tokens for new pages that are in fact empty given the provided token by the client. This breaks some of our assumptions.
This fixes that