fix: Return all obtained levels for badges #79
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.

I was wondering why I kept getting basic badges (level
1) in game even though I already had the corresponding badge with a higher level. Turns out the current implementation only returns the highest awarded level for badges due to theGROUP BY award_id + COUNT. The game server is thus told that I don't have the lower level badges yet, leading it to award the level1badge again.The endpoint needs to always return all awarded levels of a badge. The query exploded in size a bit, but I didn't really see any alternatives. Medals require the
GROUP BYto merge the individual rows into one containing theCOUNT. But badges must not be grouped and ribbons don't really care (single row anyway). Hence theUNIONof two different queries. I also moved settingfirstto zero from the write loop to the query and sorted the query results by award id and level to make the response easier to read.Note: Performance does not seem to be impacted by the change.