mirror of https://github.com/velour/catbase.git
change archive key to autoincrement
This commit is contained in:
parent
b1822efe18
commit
3cbbc4a08a
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue