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

FEAT: rebuild legacy rank and store #45

Merged
merged 2 commits into from
Jun 11, 2024
Merged

Conversation

kynrai
Copy link
Collaborator

@kynrai kynrai commented Jun 11, 2024

  • Move legacy rank to checks
  • Create stores and legacy rank in memory store
  • Only initialise the data once, the first time the handler is called, not on each call

@kynrai kynrai requested a review from Lissy93 as a code owner June 11, 2024 19:56
Copy link

codecov bot commented Jun 11, 2024

Codecov Report

Attention: Patch coverage is 58.73016% with 26 lines in your changes missing coverage. Please review.

Flag Coverage Δ
unittests 53.09% <58.73%> (+2.31%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
checks/checks.go 0.00% <0.00%> (ø)
server/server.go 0.00% <0.00%> (ø)
checks/legacy_rank.go 80.00% <80.00%> (ø)
handlers/legacy_rank.go 0.00% <0.00%> (-25.00%) ⬇️
checks/store/legacyrank/legacy_rank.go 59.18% <59.18%> (ø)

@kynrai kynrai force-pushed the feat/rebuild_legacy_rank_stores branch from 39dcefe to 0dd4ead Compare June 11, 2024 20:01
@kynrai kynrai merged commit f40dc3d into main Jun 11, 2024
3 checks passed
@kynrai kynrai deleted the feat/rebuild_legacy_rank_stores branch June 11, 2024 22:44
Copy link
Member

@Lissy93 Lissy93 left a comment

Choose a reason for hiding this comment

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

Looks awesome, thank you :)

var data map[string]int //map of domain to rank

func NewInMemoryStore() *InMemoryStore {
return &InMemoryStore{}
Copy link
Member

Choose a reason for hiding this comment

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

Why would we return the actual InMemoryStore, instead of a pointer to it? Or would that just be unnecessary here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Pointer was as i intended to originally to have the data inside the struct. but then moved it to a package with a global for the one off load, either would work here, the difference is negligible although strictly speaking non pointer would be a tiny bit faster

type InMemoryStore struct{}

var once sync.Once
var data map[string]int //map of domain to rank
Copy link
Member

Choose a reason for hiding this comment

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

Could this be encapsulated in the InMemoryStore?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This could but the once download would be per instance of memory store instead of once when the module is imported, the data would need to be at the handler level and as this is just a temporary solution, i didnt want to put it at handler level

return rank, nil
}

func load() (map[string]int, error) {
Copy link
Member

Choose a reason for hiding this comment

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

This might be able to be split up a bit smaller

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah i dont like the the fact it needs to be loaded into memory first, difference of taking in a Reader and ReaderAt with the zip reader, its possible to stream a zip file. but not with the native APIs

return rank, nil
}

func load() (map[string]int, error) {
Copy link
Member

Choose a reason for hiding this comment

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

And maybe around error handling too. As it's beeing logged but looks like it's not returned to the caller.

Maybe error handling is something i can think about at a more global level, I'm not sure how that typically works with Go, I'd need to look into it. In the JS world, I'd have a reusable error class/function, which is called whenever there's an error. So that error handling is consistent and observability/monitoring can just be implemented in one place.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Erros in golang are handled when the happen not at global level.
Errors are always bubbled up. here errors are returned to the caller which in this case logs the error.

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