Skip to content
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

Merged
merged 1 commit into from Feb 16, 2023

Conversation

Bo98
Copy link
Member

@Bo98 Bo98 commented Feb 16, 2023

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.

@Bo98 Bo98 added the critical Critical change which should be shipped as soon as possible. label Feb 16, 2023
@BrewTestBot
Copy link
Member

Review period skipped due to critical label.

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a 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.

@Bo98
Copy link
Member Author

Bo98 commented Feb 16, 2023

It also feels very weird to deliberately pass an invalid JSON string to use that parse as flow control.

We already do this by touching, but can catch ENOENT instead if you reckon nothing else here will trigger it.

@MikeMcQuaid
Copy link
Member

We already do this by touching, but can catch ENOENT instead if you reckon nothing else here will trigger it.

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.

File.touch(target)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
File.touch(target)
end
end
File.touch(target)

Are you sure we don't need to still touch if we skipped the download?

Copy link
Member Author

@Bo98 Bo98 Feb 16, 2023

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?

Library/Homebrew/api.rb Outdated Show resolved Hide resolved
@Bo98
Copy link
Member Author

Bo98 commented Feb 16, 2023

I think we should avoid attempting to parse the JSON if the file doesn't exist

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.

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.

Sounds like we want FileUtils.touch(target) unless skip_download?

@MikeMcQuaid
Copy link
Member

Sounds like we want File.touch(target) unless skip_download?

Yeh, something like that. We're using the target.mtime as the timestamp "we checked with the server and there was no updates". As long as you're testing that flow locally: I trust you to come up with the right logic here.

@Bo98
Copy link
Member Author

Bo98 commented Feb 16, 2023

We're using the target.mtime as the timestamp "we checked with the server and there was no updates".

Yeah it's a weird situation where using the server time would actually be better for --time-cond but worse for the update interval case.

Anyhow, this PR should be good now.

@MikeMcQuaid
Copy link
Member

Thanks again @Bo98!

@MikeMcQuaid MikeMcQuaid merged commit b38aca8 into Homebrew:master Feb 16, 2023
@Bo98 Bo98 deleted the no-api-write branch February 16, 2023 17:19
@github-actions github-actions bot added the outdated PR was locked due to age label Mar 19, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
critical Critical change which should be shipped as soon as possible. outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants