You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[PB-7100] refactor: build the backup folder tree with paginated folder content requests - #548
The backup ZIP download no longer calls GET /folders/{uuid}/tree. The backup folder tree is now built by walking the backup with the paginated v2 folder content endpoints (/folders/v2/content/{uuid}/files and /folders/v2/content/{uuid}/folders), following nextCursor until each folder is fully listed and fetching up to ten folders at the same time. The code lives in a new backup/remote-tree folder, next to the existing local-tree, with one small function per step. The resulting tree has the same shape the download already used, so download-folder-as-zip only changes its imports and its tests only change the path of the mocked module.
The download progress keeps working as before. The total size is the sum of the sizes of every file returned by the listing, so it is exact for any backup size, and the progress bar still compares downloaded bytes against that total. File names now come already decrypted from the server, so the local name decryption in the snapshot builder is gone. The old fetch-folder-tree-by-uuid service and its test are removed, since nothing calls /tree anymore.
Why
The /tree endpoint loads a whole folder tree in memory on the backend and was causing out of memory issues, it is deprecated and will return 410 Gone from 2.7.2. With #546 and #547 already merged, the ZIP download was the last flow still depending on it. The /stats endpoint was not an option for the progress total because it stops counting after 1000 files, and the paginated content endpoints let us get an exact size without any single heavy request.
One thing worth knowing while reviewing: cancelling a download during the listing phase only takes effect once the listing finishes, the file downloads themselves still stop right away as before.
Summary by CodeRabbit
New Features
Folder downloads now gather files and subfolders across all available pages, supporting complete nested-folder contents.
Backup snapshots include folder and file names and total file size.
Bug Fixes
Folder downloads now report errors when folder contents cannot be retrieved.
…requests
Replaces GET /folders/{uuid}/tree with GET /folders/v2/content/{uuid}/files
and /folders, walked level by level with cursor pagination. The snapshot keeps
the same shape, so the backup zip download is unchanged and its total size is
exact.
The backup ZIP flow now fetches folder contents through paginated file and subfolder requests. It assembles a remote folder tree, builds a snapshot, and passes that snapshot to the download path.
Changes: Remote backup tree
Layer / File(s)
Summary
Paginated Drive Server requests src/infra/drive-server/services/folder/services/*page.ts, src/backend/features/backup/remote-tree/fetch-all-pages.ts, src/infra/drive-server/services/folder/services/fetch-folder-tree-by-uuid.ts
Added paginated file and subfolder request functions and a shared cursor-based page fetcher. Removed the folder-tree request function. Tests cover requests, pagination, results, and errors.
Added file and subfolder fetchers that collect all pages and map results to backup-tree fields. Added a function that fetches both lists concurrently and returns errors.
Recursive tree assembly src/backend/features/backup/remote-tree/fetch-backup-folder-tree.ts, src/backend/features/backup/remote-tree/fetch-backup-folder-tree.test.ts
Added recursive tree construction with a limit of ten concurrent folder-content fetches. Tests cover tree shape, concurrency, and error propagation.
Snapshot construction src/backend/features/backup/remote-tree/types.ts, src/backend/features/backup/remote-tree/build-backup-folder-tree-snapshot.ts, src/backend/features/backup/remote-tree/get-backup-folder-tree-snapshot.ts, src/backend/features/backup/types/BackupFolderTreeSnapshot.ts, src/backend/features/backup/*snapshot*.ts
Added remote-tree types and snapshot construction using file plain names and numeric file sizes. Replaced the prior snapshot type, builder, and helper with remote-tree implementations.
ZIP download integration src/backend/features/download/download-folder-as-zip.ts, src/backend/features/download/download.test.ts, src/backend/features/backup/remote-tree/index.ts
The ZIP download path now imports the snapshot function and tree type from the remote-tree module. The download test mocks that module.
sequenceDiagram
participant downloadFolderAsZip
participant getBackupFolderTreeSnapshot
participant fetchBackupFolderTree
participant fetchFolderContent
participant DriveServer
downloadFolderAsZip->>getBackupFolderTreeSnapshot: Request snapshot for folderUuid
getBackupFolderTreeSnapshot->>fetchBackupFolderTree: Fetch tree from rootFolderUuid
fetchBackupFolderTree->>fetchFolderContent: Fetch each folder's contents
fetchFolderContent->>DriveServer: Request paginated files and subfolders
DriveServer-->>fetchFolderContent: Return page data and cursors
fetchFolderContent-->>fetchBackupFolderTree: Return files and subfolders
fetchBackupFolderTree-->>getBackupFolderTreeSnapshot: Return folder tree
getBackupFolderTreeSnapshot-->>downloadFolderAsZip: Return snapshot
Loading
Possibly related PRs
internxt/drive-desktop-linux#519: This PR also replaces the folder-tree endpoint in backup ZIP downloads with folder-content requests.
Suggested reviewers:egalvis27, victor-ferro
Merge Risk: Low · up to d666f
The backup ZIP now builds its folder tree from paginated listing requests. If the server ever returned the same cursor repeatedly, ZIP preparation could loop and consume memory. No evidence shows the server doing this, so the risk is low. A repeated-cursor check would close the gap.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: the backup folder tree is now built from paginated folder content requests instead of the deprecated /tree endpoint. The changeset adds the remote-tree flow (fetchAllP…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: the backup folder tree is now built from paginated folder content requests instead of the deprecated /tree endpoint. The changeset adds the remote-tree flow (fetchAllPages, fetchAllFolderFiles, fetchAllSubfolders, fetchBackupFolderTree, getBackupFolderTreeSnapshot) and removes fetchFolderTreeByUuid, which matches the title. The title is specific and follows the conventional prefix style. The 'PB-7100 refactor:' prefix is ticket and type metadata, not a description problem.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
22-23: Major · Stability & Availability · Quick win
Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.
Reject repeated pagination cursors.
If a response returns the requested cursor again, this loop requests the same page indefinitely. Each response appends more items. ZIP preparation cannot finish, and memory use keeps increasing.
Return an error when a nonempty nextCursor has already been used. Keep distinct cursors followed by null valid.
Based on learnings, reject an unchanged pagination cursor instead of looping.
Source: Learnings
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: defaults
Review profile: CHILL
Plan: Advanced
Run ID: 60d80c00-c03a-4231-8b0d-ec4aadb46099
Commits
Reviewing files that changed from the base of the PR and between bec7b79 and d666fdc.
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
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
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.
What is Changed / Added
The backup ZIP download no longer calls
GET /folders/{uuid}/tree. The backup folder tree is now built by walking the backup with the paginated v2 folder content endpoints (/folders/v2/content/{uuid}/filesand/folders/v2/content/{uuid}/folders), followingnextCursoruntil each folder is fully listed and fetching up to ten folders at the same time. The code lives in a newbackup/remote-treefolder, next to the existinglocal-tree, with one small function per step. The resulting tree has the same shape the download already used, sodownload-folder-as-ziponly changes its imports and its tests only change the path of the mocked module.The download progress keeps working as before. The total size is the sum of the sizes of every file returned by the listing, so it is exact for any backup size, and the progress bar still compares downloaded bytes against that total. File names now come already decrypted from the server, so the local name decryption in the snapshot builder is gone. The old
fetch-folder-tree-by-uuidservice and its test are removed, since nothing calls/treeanymore.Why
The
/treeendpoint loads a whole folder tree in memory on the backend and was causing out of memory issues, it is deprecated and will return 410 Gone from 2.7.2. With #546 and #547 already merged, the ZIP download was the last flow still depending on it. The/statsendpoint was not an option for the progress total because it stops counting after 1000 files, and the paginated content endpoints let us get an exact size without any single heavy request.One thing worth knowing while reviewing: cancelling a download during the listing phase only takes effect once the listing finishes, the file downloads themselves still stop right away as before.
Summary by CodeRabbit