Skip to content

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 confusing sort.Reverse when ordering the list.
  • Move the record types closer to the function where they are used.
  • Use a strings.Builder instead of repeated string 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.

Merge request reports

Loading