⚡ Parallelize file copy and delete operations in HarmonyOS DownloadTask#534
⚡ Parallelize file copy and delete operations in HarmonyOS DownloadTask#534
Conversation
…dTask File deletions and copies in `doPatchFromPpk` were previously executed sequentially using `await` in loops. This commit refactors these operations to use `Promise.all()`, allowing them to execute concurrently and improving overall patch application performance. Co-authored-by: sunnylqm <615282+sunnylqm@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
📝 WalkthroughWalkthroughIn Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
harmony/pushy/src/main/ets/DownloadTask.ts (1)
353-373: Parallelization looks correct; however, silent failures may leave patches in an inconsistent state.The parallel implementation is sound—copies have unique destinations (object keys), deletes target unique files, and the order (copies → deletes) is preserved via separate
Promise.all()calls.However, swallowing errors via
.catch()means a failed copy or delete won't stop the operation—the function proceeds and eventually succeeds. If a critical file fails to copy, the patch could be incomplete or broken at runtime. Consider either:
- Collecting failed operations and throwing after all complete (fail-fast with aggregated errors):
Example: Aggregate errors
- await Promise.all( - Object.entries(copies as Record<string, string>).map(([to, from]) => - fileIo - .copyFile( - `${params.originDirectory}/${from}`, - `${params.unzipDirectory}/${to}`, - ) - .catch(error => { - console.error('copy error:', error); - }), - ), - ); + const copyErrors: Array<{ file: string; error: unknown }> = []; + await Promise.all( + Object.entries(copies as Record<string, string>).map(([to, from]) => + fileIo + .copyFile( + `${params.originDirectory}/${from}`, + `${params.unzipDirectory}/${to}`, + ) + .catch(error => { + console.error('copy error:', error); + copyErrors.push({ file: to, error }); + }), + ), + ); + if (copyErrors.length > 0) { + throw new Error(`Failed to copy ${copyErrors.length} file(s)`); + }
- Using
Promise.allSettled()to continue on failure but still report issues.If the current swallow-and-continue behavior is intentional (best-effort patching), a brief comment explaining the rationale would help future maintainers.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@harmony/pushy/src/main/ets/DownloadTask.ts` around lines 353 - 373, The current parallel copy/delete logic swallows errors via .catch() on each Promise, risking silent incomplete patches; update the block around fileIo.copyFile and fileIo.unlink (operating on copies, deletes with params.originDirectory and params.unzipDirectory) to collect failures and surface them after all operations complete: either use Promise.allSettled() and aggregate any rejected results into a single thrown Error (or structured error report) or remove the per-item .catch() and let Promise.all reject to fail-fast; if best-effort behavior is intentional, add a concise comment explaining that choice and ensure errors are still logged and reported to callers.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@harmony/pushy/src/main/ets/DownloadTask.ts`:
- Around line 353-373: The current parallel copy/delete logic swallows errors
via .catch() on each Promise, risking silent incomplete patches; update the
block around fileIo.copyFile and fileIo.unlink (operating on copies, deletes
with params.originDirectory and params.unzipDirectory) to collect failures and
surface them after all operations complete: either use Promise.allSettled() and
aggregate any rejected results into a single thrown Error (or structured error
report) or remove the per-item .catch() and let Promise.all reject to fail-fast;
if best-effort behavior is intentional, add a concise comment explaining that
choice and ensure errors are still logged and reported to callers.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ffbc5434-2e77-4e78-be32-23ec8e04597c
📒 Files selected for processing (1)
harmony/pushy/src/main/ets/DownloadTask.ts
awaitloops forcopyFileandunlinkinharmony/pushy/src/main/ets/DownloadTask.ts.Promise.all().PR created automatically by Jules for task 9441733629852452380 started by @sunnylqm
Summary by CodeRabbit