GWI Go Platform Challenge#71
Conversation
ba091724
left a comment
There was a problem hiding this comment.
Hello @LeoStavropoulos
Thank you for taking the time to design and implement the assignment!
I have added a couple of comments for you to look when you have the time.
I would also like to get your opinion regarding the following scenario:
Let's consider that this project is part of a large system allowing users to save their favorites among a huge amount of assets persisted under an entity table Assets. Would you approach this implementation in a different way?
| mux.Handle("POST /favorites", auth(http.HandlerFunc(h.Create))) | ||
| // mux.Handle("GET /favorites/mine", auth(http.HandlerFunc(h.ListMine))) // Removed, redundant | ||
| mux.Handle("DELETE /favorites/{id}", auth(http.HandlerFunc(h.Delete))) | ||
| mux.Handle("PATCH /favorites/{id}", auth(http.HandlerFunc(h.UpdateDescription))) |
There was a problem hiding this comment.
Can you spot any issues with the way this endpoint behaves?
There was a problem hiding this comment.
Actually after reviewing it I can see a “semantic” issue in both the delete and updateDescription methods. They are returning a 500 status code instead of 404 for missing assets. Also, the error matching logic is a bit unreliable. If the error message changes, the code stops working properly. A typed error would be a better approach.
| start := int64(offset) | ||
| stop := int64(offset + limit - 1) | ||
|
|
||
| ids, err := s.cache.GetIdsFromSet(ctx, start, stop) |
There was a problem hiding this comment.
Well done considering caching!
I saw your comment about a later application on FindAllByUser, all good and well.
Is there a reason for prioritising caching on FindAll over FindAllByUser?
There was a problem hiding this comment.
The global findAll query is the most dangerous, performance wise, operation of this service. In a large database, offset queries would be slow and could lead to resources locking. On the other hand, the findAllByUser is scoped by an index on user_id, so it could have decent performance even without caching.
| mux.Handle("GET /favorites/{id}", auth(http.HandlerFunc(h.Get))) | ||
| mux.Handle("POST /favorites", auth(http.HandlerFunc(h.Create))) | ||
| // mux.Handle("GET /favorites/mine", auth(http.HandlerFunc(h.ListMine))) // Removed, redundant | ||
| mux.Handle("DELETE /favorites/{id}", auth(http.HandlerFunc(h.Delete))) |
There was a problem hiding this comment.
Can you spot any issues with the way this endpoint behaves?
|
Hello @ba091724 First of all, thank you for your time and effort reviewing my assessment and apologies for the late response. |
No description provided.