Refactor displayCountryStats
Some refactoring and clarity changes around displayCountryStats
in the broker metrics code.
The function gets renamed formatAndClearCountryStats
to highlight the fact
that it has a side effect of clearing the map,
which is necessary for proper daily metrics reporting (cf. !606 (merged)).
- Swap the order of the
sort.Interface.Less
function, to avoid a confusingsort.Reverse
when ordering the list. - Move the
record
types closer to the function where they are used. - Use a
strings.Builder
instead of repeatedstring
concatenation. - Don't redundantly look up the count for each country, when
sync.Map.Range
already gives us that. - Add documentation comments.
- Add a test that the map gets cleared after the function is called.