-
Notifications
You must be signed in to change notification settings - Fork 136
Add overloads for snapshot functions to expose download speed #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@adrgrondin Great contribution thank you! Could we add a test that accumulates some recorded speed in an array or something for a given download? Just to be sure it doesn't get broken in the future :) Also |
Thanks @FL33TW00D I added a I can run |
LGTM cc: @pcuenca |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Appreciate the carefulness in keeping it non-breaking 🙌
We use a pinned version of the formatter because we've seen great rule divergence (as you experienced too). I took the liberty to run it locally and commit to your PR.
if let speed { | ||
fileProgress.setUserInfoObject(speed, forKey: .throughputKey) | ||
progress.setUserInfoObject(speed, forKey: .throughputKey) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
@discardableResult func snapshot(from repo: Repo, revision: String = "main", matching globs: [String] = [], progressHandler: @escaping (Progress, Double?) -> Void) async throws -> URL { | ||
try await snapshot(from: repo, revision: revision, matching: globs) { progress in | ||
let speed = progress.userInfo[.throughputKey] as? Double | ||
progressHandler(progress, speed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, this is just a shortcut for the value in .throughputKey
👍
@@ -64,18 +64,17 @@ struct Download: AsyncParsableCommand, SubcommandWithToken { | |||
DispatchQueue.main.async { | |||
let totalPercent = 100 * progress.fractionCompleted | |||
let speedBps = progress.userInfo[.throughputKey] as? Double | |||
let speedString: String | |||
if let s = speedBps { | |||
let speedString = if let s = speedBps { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
honestly, I hate that the formatter gets involved with this at all 😭 The previous version was clearer in my opinion cc @FL33TW00D @adrgrondin
Apologies for the failed CI run, we are in the process of fixing it. Tests pass locally, so merging! |
Summary
This PR introduces new overloads for the
snapshot
functions’ progress handlers that expose download speed (in bytes/s).The new overloads are fully backward compatible, existing APIs remain unchanged.
Changes
Download speed printed in code compared against Xcode’s Network Report: