followee_favorites and followee_reposts match v1 api. #10
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This was annoying. The options considered:
GetTracksquery. But it does mean getting 10 tracks incurs 20 additional queries for these fields.followee_favoritesand one forfollowee_reposts. Use window function to get the relevant rows grouped by each track ID. Elemental does something similar in this query.With both of these you do the familiar pattern of:
Which is all fine I guess.
Anyway in this PR I tried the 3rd approach which is to use postgres features to build up a json result in the base query itself. I hit a few sqlc snags initially but adding
::jsonbto the column type mostly made things work.And I could have called it done with just a query change were it not for the mf hashids. So then I defined struct to match json and unmarshal and loop over and encode the hashids.
I spent too long trying to write a generic recursive hash ID encoder that would just modify the JSON on the way out. Stupid hash IDs. Anyway me and ChatGPT got pretty close but I gave up on that for now. Might revisit later.