Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Split Warmer.warm() into smaller functions #1935

Merged
merged 2 commits into from
Apr 15, 2019

Conversation

2opremio
Copy link
Contributor

@2opremio 2opremio commented Apr 14, 2019

Warmer.warming() was a huge function (~250 loc), making it really hard to read.

This change splits the warmer into smaller functions, improving readability.

After this change Warmer.warming() is still 100 loc, but reads much better.

@2opremio 2opremio changed the title Split Warmer.warm() into smaller functions [WIP] Split Warmer.warm() into smaller functions Apr 14, 2019
@2opremio 2opremio force-pushed the refactor-warmer branch 3 times, most recently from fe1d18a to dcd3fb3 Compare April 15, 2019 13:09
`Warmer.warming()` was a huge function (~250 loc), making it really hard to read.

This change moves most of it into a new `repoCacheManager`, improving readability.

After this change `Warmer.warming()` is still 100 loc, but reads much better.
@2opremio 2opremio requested a review from hiddeco April 15, 2019 13:40
@2opremio 2opremio changed the title [WIP] Split Warmer.warm() into smaller functions Split Warmer.warm() into smaller functions Apr 15, 2019
// updateImages, refreshes the cache entries for the images passed. It may not succeed for all images.
// It returns the values stored in cache, the number of images it succeeded for and the number
// of images whose manifest wasn't found in the registry.
func (c *repoCacheManager) updateImages(ctx context.Context, registryClient registry.Client, images []imageToUpdate) (map[string]image.Info, int, int) {
Copy link
Member

Choose a reason for hiding this comment

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

Just a note; I am not a fan of the .., int, int return, but wrapping it in a struct to give it more context does not seem very meaningful either, the comment makes up for it a bit though.

Copy link
Contributor Author

@2opremio 2opremio Apr 15, 2019

Choose a reason for hiding this comment

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

Yeah, I am not too pleased with this or fetchImagesResult either

Happy to look into any suggestions you may have.

Maybe computing the counters outside of the functions? I gave that a short chance but it was hairy. I will give it another try.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't find a cleaner way. At least not with a much bigger refactoring.

Copy link
Member

@hiddeco hiddeco left a comment

Choose a reason for hiding this comment

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

My mind is very pleased with the readability improvement 🌠

@2opremio 2opremio merged commit 686acaa into fluxcd:master Apr 15, 2019
@2opremio 2opremio deleted the refactor-warmer branch April 15, 2019 22:09
@squaremo squaremo added this to the v1.12.1 milestone Apr 24, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants