perf: skip is_package() network call for already-synced Drive files#449
Merged
Conversation
Drive sync was making one HTTP network request per file via is_package() before checking whether the file already existed locally. For thousands of already-synced files this caused significant unnecessary latency. Now collect_file_for_download() and process_file() check local existence first (no network call): - If local file exists and is up-to-date → skip immediately - If local directory exists and package is up-to-date → skip immediately - If local directory exists but package is outdated → mark as package for re-download (avoids is_package() call by inferring type from filesystem) - Only call is_package() when neither local file nor directory exists" Agent-Logs-Url: https://github.com/mandarons/icloud-docker/sessions/628ead08-5a77-4a33-b669-8899f8477db8 Co-authored-by: mandarons <50469173+mandarons@users.noreply.github.com>
…ogic Agent-Logs-Url: https://github.com/mandarons/icloud-docker/sessions/628ead08-5a77-4a33-b669-8899f8477db8 Co-authored-by: mandarons <50469173+mandarons@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix long duration for drive synchronization without transfers
perf: skip is_package() network call for already-synced Drive files
May 20, 2026
Agent-Logs-Url: https://github.com/mandarons/icloud-docker/sessions/4e1bdea4-3afc-44bd-9727-173813c1a3b9 Co-authored-by: mandarons <50469173+mandarons@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves iCloud Drive sync performance by avoiding the expensive is_package() HTTP request for items that are already present locally and up-to-date. It updates both the parallel download path and the legacy process_file() path to check local existence first, and adds targeted tests to keep coverage at 100%.
Changes:
- Reordered Drive sync decision logic to check
os.path.isfile()/os.path.isdir()and local freshness (file_exists()/package_exists()) before callingis_package(). - Added an early-return download-task path for “outdated local package directory” cases to re-download packages without an extra
is_package()network call. - Added/expanded unit tests to cover
package_exists()edge cases and the new early-return behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/drive_parallel_download.py |
Skips is_package() for already-synced files/packages by checking local existence first; adds fast re-download scheduling for outdated package dirs. |
src/sync_drive.py |
Applies the same optimization to legacy process_file() and simplifies the control flow with an explicit if/elif/else structure. |
tests/test_sync_drive.py |
Adds tests covering package_exists() falsey cases and the new “outdated package dir” early-return path in collect_file_for_download. |
mandarons
approved these changes
May 21, 2026
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.
is_package()indrive_parallel_download.pymakes a network request for every file before checking local existencecollect_file_for_downloadindrive_parallel_download.pyto check local file existence FIRST before making any network requestprocess_fileinsync_drive.py(legacy function) with same optimization, eliminating duplicate package post-download code via if/elif/else structurepackage_exists()and the directory-implies-package assumptiontest_collect_file_for_download_package_outdatedto cover the new early-return path for outdated package directoriesdrive_file_existence.pylines 68-69 lost coverage because the new code only callspackage_exists()whenos.path.isdir()is True (old code called it for first-time package downloads with non-existent paths)test_package_exists_none_itemandtest_package_exists_non_existent_pathto restore 100% coverage ofdrive_file_existence.py