Skip to content

Implement mitigation for server returning empty pages#90

Merged
claucambra merged 4 commits into
mainfrom
bugfix/pagination-pt6
Jun 11, 2025
Merged

Implement mitigation for server returning empty pages#90
claucambra merged 4 commits into
mainfrom
bugfix/pagination-pt6

Conversation

@claucambra
Copy link
Copy Markdown
Contributor

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

…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>
@claucambra claucambra added this to the 3.0 milestone Jun 11, 2025
@claucambra claucambra requested a review from Copilot June 11, 2025 17:35
@claucambra claucambra self-assigned this Jun 11, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 testWorkingSetEnumerationStopsOnExhaustedTotal to verify the paginator halts on empty pages.
  • A forceNextPageOnLastContentPage flag in MockRemoteInterface to simulate faulty servers.
  • Updates in EnumeratorPageResponse, Enumerator, and the sync‐engine extension to track and apply total counts 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 total may 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)

Comment thread Sources/NextcloudFileProviderKit/Enumeration/Enumerator.swift
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 11, 2025

Codecov Report

Attention: Patch coverage is 91.07143% with 10 lines in your changes missing coverage. Please review.

Project coverage is 84.00%. Comparing base (a869466) to head (0622638).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
...tcloudFileProviderKit/Enumeration/Enumerator.swift 73.68% 5 Missing ⚠️
...roviderKit/Enumeration/Enumerator+SyncEngine.swift 0.00% 3 Missing ⚠️
Tests/Interface/MockRemoteInterface.swift 60.00% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@claucambra claucambra merged commit 044f351 into main Jun 11, 2025
3 checks passed
@claucambra claucambra deleted the bugfix/pagination-pt6 branch June 11, 2025 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants