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
api: avoid unnecessary file write operation #14666
Conversation
Review period skipped due to |
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.
This will break the (Time.now - Homebrew::EnvConfig.api_auto_update_secs.to_i) < target.mtime)
handling because we use the time from the server.
It also feels very weird to deliberately pass an invalid JSON string to use that parse as flow control.
We already do this by |
I think we should avoid attempting to parse the JSON if the file doesn't exist. If the file does exist: we need to touch it every time we've checked for a download, even if we didn't download anything new. |
Library/Homebrew/api.rb
Outdated
File.touch(target) | ||
end |
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.
File.touch(target) | |
end | |
end | |
File.touch(target) |
Are you sure we don't need to still touch if we skipped the download?
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.
That would just cause it to drift to 450 seconds after the last brew command rather than 450 seconds after the last update attempt, no?
The retry flow sounds messy for that scenario, but I suppose it should maybe always exist at that point so probably safe to ignore, yeah.
Sounds like we want |
Yeh, something like that. We're using the |
Yeah it's a weird situation where using the server time would actually be better for Anyhow, this PR should be good now. |
Thanks again @Bo98! |
Fixes the
HOMEBREW_NO_AUTO_UPDATE
part of #14663.File.touch
always modifies the file, even if it already exists, because it refreshes mtime etc.