Skip to content

fix: keep the WebDAV pagination token across cached pages - #4481

Open
jeldriks wants to merge 1 commit into
nextcloud:masterfrom
jeldriks:fix/keep-pagination-token
Open

jeldriks wants to merge 1 commit into
nextcloud:masterfrom
jeldriks:fix/keep-pagination-token

Conversation

@jeldriks

Copy link
Copy Markdown

Summary

Keep the WebDAV pagination token across all pages of a paginated listing.

Nextcloud's paginated PROPFIND/SEARCH returns X-NC-Paginate-Token and X-NC-Paginate-Total only with the first page. Follow-up pages are served from the server's pagination cache and carry only X-NC-Paginate: true; clients are expected to keep the token (NC 31 developer notes, nextcloud/server#10880).

Two places overwrote the token with each response, so it became nil after the first cached page. The next request then went without a token, and the server built and cached the full listing again under a new token:

  • In the File Provider (Files app), every second page of a large folder triggered a full server-side re-listing.
  • In the media metadata backfill, pages after the first cached one restarted the full media SEARCH.

Changes

  • FileProviderEnumerator: keep the previous token when a response has none. When a listing restarts at page 0, reset the token, total and page counts, so it never continues from an earlier listing's cached result or offsets.
  • NCMediaMetadataBackfillProcessor: keep the previous token when a response has none. The token is local to one batch, so it is never reused across searches.

NCMediaNetwork already handled this correctly and is unchanged.

How to verify

  1. Enable the account's location in the Files app and open a folder with more than one page of entries (> 200 files in release builds, > 50 in debug).
  2. In the server's access log (or the X-NC-Paginate-* request headers), every follow-up request of the listing should carry the same token and come back quickly. Before this change, every second request has no token and takes as long as the first.
  3. Add a file on the server and reopen the folder: the listing starts fresh and the file appears once its page is reached.

Tested

Live test against a Nextcloud 35.0.3 server (iOS 27.2 simulator, debug build with 50 entries per page), listing a folder with 7,469 files in the Files app:

Without this change With this change
Token lost on every second page; a new one every 2 pages one token for the whole listing
Full server-side listings every second request first request only
Time per page (avg) 5.2 s 1.6 s
Whole folder ~13 min (projected from 86 pages in 446 s) 151 requests in 236 s
  • Reopening the folder started a fresh listing (page 0 without a token); a file added on the server appeared.
  • File Provider Extension and Nextcloud schemes build; SwiftLint reports no new findings.
  • The media metadata backfill change was not exercised in this test.

No unit tests: FileProviderEnumerator belongs to the extension target, which NextcloudUnitTests cannot import, and the backfill change is a single ?? fallback. I can extract the paging state into a testable type if you prefer.

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI (N/A)

Investigation, code and this description were drafted with Claude Code (claude-opus-5-5) and reviewed by me.

Paginated PROPFIND/SEARCH responses carry X-NC-Paginate-Token only
with the first page; follow-up pages are served from the server's
pagination cache with only X-NC-Paginate: true. The File Provider
enumerator and the media metadata backfill overwrote the token with
each response, so it became nil after the first cached page and the
server rebuilt the full listing on every second request.

- Keep the previous token when a paginated response has none.
- Reset token, total and page counts when the File Provider listing
  restarts at page 0, so it never continues an earlier cached result.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Jeldrik Schröer <jeldrik@jschroeer.de>
@jeldriks
jeldriks force-pushed the fix/keep-pagination-token branch from 708496c to c9ba6bc Compare November 21, 2026 16:52
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.

1 participant