refactor: modularize concurrent downloader logic by extracting helper methods and state management into dedicated routines - #444
#444Merged
Merged
refactor: modularize concurrent downloader logic by extracting helper methods and state management into dedicated routines#444
Conversation
… methods and state management into dedicated routines
…pletion, and add regression tests
…ing anonymous functions
StressTestor
pushed a commit
to StressTestor/Surge
that referenced
this pull request
Jun 1, 2026
… methods and state management into dedicated routines (SurgeDM#444)
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.
Greptile Summary
This PR refactors the monolithic
Downloadmethod in the concurrent downloader by extracting its internal phases into dedicated methods (initMirrorStatus,setupNetwork,getWorkerMirrors,setupTasks,startHelpers,runBalancer,runCompletionMonitor,runHealthMonitor,executeWorkers,handlePause,syncFile). A companion test file covers the extracted helpers.runCompletionMonitorby guardingd.State.Downloaded.Load()behind ad.State != nilcheck that the original inline goroutine lacked.executeWorkersnow deduplicates and joins multiple worker errors witherrors.Joininstead of silently overwriting with the last error, surfacing all unique failure causes to callers.InitBitmap\u2192setupTasks/RestoreBitmap) is preserved correctly, and the pause-at-completion-boundary path now explicitly returnsd.syncFile(outFile)rather than falling through to the cancel check.Confidence Score: 5/5
Safe to merge; the extracted helpers preserve the original control flow and the only finding is a redundant test.
The decomposition is mechanically faithful to the original logic, the defer ordering is correct, the nil-guard improvement is sound, and the new tests cover the key extracted paths. No functional regressions were identified.
No files require special attention.
Important Files Changed
Prompt To Fix All With AI
Reviews (3): Last reviewed commit: "Merge branch 'main' into speed-limit-hnd..." | Re-trigger Greptile