From 3cbbc4a08a871d0b877840e49c73a4e294153e78 Mon Sep 17 00:00:00 2001 From: Chris Sexton <3216719+chrissexton@users.noreply.github.com> Date: Wed, 22 Dec 2021 14:05:59 -0500 Subject: [PATCH] change archive key to autoincrement --- plugins/countdown/countdown.go | 9 +++------ plugins/countdown/countdown_test.go | 6 +++++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/plugins/countdown/countdown.go b/plugins/countdown/countdown.go index d469e7b..34cff61 100644 --- a/plugins/countdown/countdown.go +++ b/plugins/countdown/countdown.go @@ -85,13 +85,10 @@ func (p *CountdownPlugin) clearBabblers() error { type counterArchive struct { counter.Item + ID uint64 `boltholdKey:"ID"` Year int } -func (ca counterArchive) Key() string { - return fmt.Sprintf("%d-%d", ca.Year, ca.ID) -} - func (p *CountdownPlugin) archiveCounters() error { year := time.Now().Year() allCounters := []counter.Item{} @@ -100,8 +97,8 @@ func (p *CountdownPlugin) archiveCounters() error { return err } for _, c := range allCounters { - ca := counterArchive{c, year} - err := p.store.Insert(ca.Key(), ca) + ca := counterArchive{Item: c, Year: year} + err := p.store.Insert(bh.NextSequence(), &ca) if err != nil { return err } diff --git a/plugins/countdown/countdown_test.go b/plugins/countdown/countdown_test.go index 6fe557b..da18c16 100644 --- a/plugins/countdown/countdown_test.go +++ b/plugins/countdown/countdown_test.go @@ -89,7 +89,7 @@ func TestArchiveCounters(t *testing.T) { } count, err := mb.Store().Count(counter.Item{}, &bh.Query{}) assert.Nil(t, err) - assert.Greater(t, count, 0) + assert.Equal(t, count, 3) err = cd.archiveCounters() assert.Nil(t, err) @@ -97,4 +97,8 @@ func TestArchiveCounters(t *testing.T) { count, err = mb.Store().Count(counter.Item{}, &bh.Query{}) assert.Nil(t, err) assert.Equal(t, count, 0) + + count, err = mb.Store().Count(counterArchive{}, &bh.Query{}) + assert.Nil(t, err) + assert.Equal(t, count, 3) }