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

Optimize computeRoutePrefix #584

Merged
merged 4 commits into from
Oct 21, 2023
Merged

Optimize computeRoutePrefix #584

merged 4 commits into from
Oct 21, 2023

Conversation

donuts-are-good
Copy link
Contributor

Previously, computeRoutePrefix was adding a '/' to the start of the prefix and then removing it from the end, regardless of whether it was there or not. This resulted in unnecessary string operations. The updated function only adds or removes the '/' when necessary, improving efficiency. Additionally, the function now uses strings.HasPrefix and strings.HasSuffix for clearer intent and readability.

Previously, computeRoutePrefix was adding a '/' to the start of the prefix and then removing it from the end, regardless of whether it was there or not. This resulted in unnecessary string operations. The updated function only adds or removes the '/' when necessary, improving efficiency. Additionally, the function now uses strings.HasPrefix and strings.HasSuffix for clearer intent and readability.

Signed-off-by: donuts-are-good <[email protected]>
@beorn7
Copy link
Member

beorn7 commented Oct 8, 2023

Thank you. I'll have a look ASAP. Could you fix the gofmt issue flagged by the CI test in the meantime?

@donuts-are-good
Copy link
Contributor Author

Good morning @beorn7, and thank you for the reply. I will do that when I return to my desk this afternoon after family time :)

@donuts-are-good
Copy link
Contributor Author

donuts-are-good commented Oct 9, 2023

Bit embarrassed to ask, but what is it that is needed here?

  • The snippet in the CI error is located in a file that was not modified by this PR, (though the PR was crafted on darwin/arm64 so perhaps inadvertently that caused an issue).
  • Running gofmt -w main.go on the file containing that snippet (from linux/amd64) shows that there is nothing to commit after, no changes.
  • Running gofmt -w ./handlers/push.go on the file that received the changes shows that there is nothing to commit after running gofmt from linux/amd64.

image

image

@beorn7
Copy link
Member

beorn7 commented Oct 9, 2023

Maybe you are using an old Go version?

Line 10 is a spurious blank line.

@donuts-are-good
Copy link
Contributor Author

I'm using 1.21.1, I'll see if removing that line helps. Thanks for the tip!

This change is to remove an extra blank line above shutdownServerOnQuit() that could possibly be the source of a CI test error. 

Signed-off-by: donuts-are-good <[email protected]>
@donuts-are-good
Copy link
Contributor Author

Yahtzee!

@donuts-are-good
Copy link
Contributor Author

Is there anything else I should do, or just sit tight and wait?

Copy link
Member

@beorn7 beorn7 left a comment

Choose a reason for hiding this comment

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

Thank you. Looks good in general, but L263 isn't needed, and I have some Promethean nit picking about punctuation. See comments.

Apologies for the review delay. I generally have to fight a lengthy review backlog, and on top of that, I have been at SREcon all week long.

main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
@donuts-are-good
Copy link
Contributor Author

Thank you. Looks good in general, but L263 isn't needed, and I have some Promethean nit picking about punctuation. See comments.

Apologies for the review delay. I generally have to fight a lengthy review backlog, and on top of that, I have been at SREcon all week long.

Sounds good, I'll get this taken care of early this week. Hope it was a good trip, thanks for the feedback :)

It was pointed out to me that these comments were lacking final punctuation. This commit adds punctuation.

Signed-off-by: donuts-are-good <[email protected]>
It was pointed out that strings.TrimSuffix already contained the functionality added here, removing the conditional that added HasSuffix

Signed-off-by: donuts-are-good <[email protected]>
@beorn7 beorn7 merged commit ec7afda into prometheus:master Oct 21, 2023
2 checks passed
@donuts-are-good
Copy link
Contributor Author

What an awesome gift to see when I log in to Github today. Thank you for your time and guidance on this PR @beorn7

@donuts-are-good donuts-are-good deleted the patch-1 branch October 21, 2023 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants