Skip to content

[PB-7100] refactor: build the backup folder tree with paginated folder content requests - #548

Merged
AlexisMora merged 4 commits into
mainfrom
refactor/pb-7100-backup-zip-download-folder-content
Dec 4, 2026
Merged

AlexisMora merged 4 commits into
mainfrom
refactor/pb-7100-backup-zip-download-folder-content

Conversation

@AlexisMora

@AlexisMora AlexisMora commented Dec 4, 2026 •

Copy link
Copy Markdown

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}/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.
@coderabbitai

coderabbitai Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

Explain Change →

Walkthrough

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.
Folder content fetching
src/backend/features/backup/remote-tree/fetch-all-folder-files.ts, src/backend/features/backup/remote-tree/fetch-all-subfolders.ts, src/backend/features/backup/remote-tree/fetch-folder-content.ts, src/backend/features/backup/remote-tree/*test.ts
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.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Sequence Diagram(s)

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

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: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 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 Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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.

Share

@AlexisMora
AlexisMora marked this pull request as ready for review December 4, 2026 14:21

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Additional comments: 1

src/backend/features/backup/remote-tree/fetch-all-pages.ts-22-23: 1

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.

Files selected for processing: 28

  • src/backend/features/backup/build-backup-folder-tree-snapshot.ts
  • src/backend/features/backup/get-backup-folder-tree-snapshot.test.ts
  • src/backend/features/backup/get-backup-folder-tree-snapshot.ts
  • src/backend/features/backup/remote-tree/build-backup-folder-tree-snapshot.test.ts
  • src/backend/features/backup/remote-tree/build-backup-folder-tree-snapshot.ts
  • src/backend/features/backup/remote-tree/fetch-all-folder-files.test.ts
  • src/backend/features/backup/remote-tree/fetch-all-folder-files.ts
  • src/backend/features/backup/remote-tree/fetch-all-pages.test.ts
  • src/backend/features/backup/remote-tree/fetch-all-pages.ts
  • src/backend/features/backup/remote-tree/fetch-all-subfolders.test.ts
  • src/backend/features/backup/remote-tree/fetch-all-subfolders.ts
  • src/backend/features/backup/remote-tree/fetch-backup-folder-tree.test.ts
  • src/backend/features/backup/remote-tree/fetch-backup-folder-tree.ts
  • src/backend/features/backup/remote-tree/fetch-folder-content.test.ts
  • src/backend/features/backup/remote-tree/fetch-folder-content.ts
  • src/backend/features/backup/remote-tree/get-backup-folder-tree-snapshot.test.ts
  • src/backend/features/backup/remote-tree/get-backup-folder-tree-snapshot.ts
  • src/backend/features/backup/remote-tree/index.ts
  • src/backend/features/backup/remote-tree/types.ts
  • src/backend/features/backup/types/BackupFolderTreeSnapshot.ts
  • src/backend/features/download/download-folder-as-zip.ts
  • src/backend/features/download/download.test.ts
  • src/infra/drive-server/services/folder/services/fetch-folder-files-page.test.ts
  • src/infra/drive-server/services/folder/services/fetch-folder-files-page.ts
  • src/infra/drive-server/services/folder/services/fetch-folder-subfolders-page.test.ts
  • src/infra/drive-server/services/folder/services/fetch-folder-subfolders-page.ts
  • src/infra/drive-server/services/folder/services/fetch-folder-tree-by-uuid.test.ts
  • src/infra/drive-server/services/folder/services/fetch-folder-tree-by-uuid.ts
Files with no reviewable changes: 6

  • src/backend/features/backup/build-backup-folder-tree-snapshot.ts
  • src/backend/features/backup/get-backup-folder-tree-snapshot.test.ts
  • src/backend/features/backup/get-backup-folder-tree-snapshot.ts
  • src/backend/features/backup/types/BackupFolderTreeSnapshot.ts
  • src/infra/drive-server/services/folder/services/fetch-folder-tree-by-uuid.test.ts
  • src/infra/drive-server/services/folder/services/fetch-folder-tree-by-uuid.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@sonarqubecloud

sonarqubecloud Bot commented Dec 4, 2026

Copy link
Copy Markdown

@AlexisMora
AlexisMora merged commit 6f4d177 into main Dec 4, 2026
16 checks passed
@AlexisMora
AlexisMora deleted the refactor/pb-7100-backup-zip-download-folder-content branch December 4, 2026 15:43
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