-
-
Notifications
You must be signed in to change notification settings - Fork 5
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
Conversation
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
Codecov ReportAttention: Patch coverage is
Flags with carried forward coverage won't be shown. Click here to find out more.
|
39dcefe
to
0dd4ead
Compare
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.
Looks awesome, thank you :)
var data map[string]int //map of domain to rank | ||
|
||
func NewInMemoryStore() *InMemoryStore { | ||
return &InMemoryStore{} |
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.
Why would we return the actual InMemoryStore, instead of a pointer to it? Or would that just be unnecessary here?
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.
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 |
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.
Could this be encapsulated in the InMemoryStore
?
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 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) { |
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 might be able to be split up a bit smaller
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.
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) { |
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.
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.
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.
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.