From c950b2c38b3ad77157b91435e07ea066dbc741e0 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Sun, 20 Feb 2022 15:15:16 +0100 Subject: [PATCH] [counter] Remove stored counter value on zero value Rationale: The counter store is of `map[string]int64` and therefor for an non-existent counter always `0`. As that is the default behaviour we don't need to waste storage space by storing counters being `0`. Signed-off-by: Knut Ahlers --- store.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/store.go b/store.go index 084183a..32b58ea 100644 --- a/store.go +++ b/store.go @@ -294,7 +294,11 @@ func (s *storageFile) UpdateCounter(counter string, value int64, absolute bool) value = s.Counters[counter] + value } - s.Counters[counter] = value + if value == 0 { + delete(s.Counters, counter) + } else { + s.Counters[counter] = value + } return errors.Wrap(s.Save(), "saving store") }