change archive key to autoincrement

This commit is contained in:
Chris Sexton 2021-12-22 14:05:59 -05:00
parent b1822efe18
commit 3cbbc4a08a
2 changed files with 8 additions and 7 deletions

View File

@ -85,13 +85,10 @@ func (p *CountdownPlugin) clearBabblers() error {
type counterArchive struct { type counterArchive struct {
counter.Item counter.Item
ID uint64 `boltholdKey:"ID"`
Year int Year int
} }
func (ca counterArchive) Key() string {
return fmt.Sprintf("%d-%d", ca.Year, ca.ID)
}
func (p *CountdownPlugin) archiveCounters() error { func (p *CountdownPlugin) archiveCounters() error {
year := time.Now().Year() year := time.Now().Year()
allCounters := []counter.Item{} allCounters := []counter.Item{}
@ -100,8 +97,8 @@ func (p *CountdownPlugin) archiveCounters() error {
return err return err
} }
for _, c := range allCounters { for _, c := range allCounters {
ca := counterArchive{c, year} ca := counterArchive{Item: c, Year: year}
err := p.store.Insert(ca.Key(), ca) err := p.store.Insert(bh.NextSequence(), &ca)
if err != nil { if err != nil {
return err return err
} }

View File

@ -89,7 +89,7 @@ func TestArchiveCounters(t *testing.T) {
} }
count, err := mb.Store().Count(counter.Item{}, &bh.Query{}) count, err := mb.Store().Count(counter.Item{}, &bh.Query{})
assert.Nil(t, err) assert.Nil(t, err)
assert.Greater(t, count, 0) assert.Equal(t, count, 3)
err = cd.archiveCounters() err = cd.archiveCounters()
assert.Nil(t, err) assert.Nil(t, err)
@ -97,4 +97,8 @@ func TestArchiveCounters(t *testing.T) {
count, err = mb.Store().Count(counter.Item{}, &bh.Query{}) count, err = mb.Store().Count(counter.Item{}, &bh.Query{})
assert.Nil(t, err) assert.Nil(t, err)
assert.Equal(t, count, 0) assert.Equal(t, count, 0)
count, err = mb.Store().Count(counterArchive{}, &bh.Query{})
assert.Nil(t, err)
assert.Equal(t, count, 3)
} }