Skip to content

Commit

Permalink
use update time instead of decoding order
Browse files Browse the repository at this point in the history
  • Loading branch information
buck54321 committed Sep 16, 2024
1 parent 65179f1 commit 43e8f54
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
15 changes: 10 additions & 5 deletions client/db/bolt/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ func (db *BoltDB) pruneArchivedOrders() error {

type orderStamp struct {
oid []byte
stamp int64
stamp uint64
}
deletes := make([]*orderStamp, 0, toClear)
sortDeletes := func() {
Expand All @@ -485,11 +485,16 @@ func (db *BoltDB) pruneArchivedOrders() error {
if _, found := oidsWithActiveMatches[oid]; found {
return nil
}
ord, err := decodeOrderBucket(oidB, archivedOB.Bucket(oidB))
if err != nil {
return fmt.Errorf("error decoding order %x: %v", oid, err)
oBkt := archivedOB.Bucket(oidB)
if oBkt == nil {
return fmt.Errorf("no order bucket iterated order %x", oidB)
}
stampB := oBkt.Get(updateTimeKey)
if stampB == nil {
// Highly improbable.
stampB = make([]byte, 8)
}
stamp := ord.Order.Prefix().ClientTime.Unix()
stamp := intCoder.Uint64(stampB)
if len(deletes) < toClear {
deletes = append(deletes, &orderStamp{
stamp: stamp,
Expand Down
7 changes: 6 additions & 1 deletion client/db/bolt/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1644,7 +1644,12 @@ func TestPruneArchivedOrders(t *testing.T) {
},
Order: ord,
})
return ord.ID()
oid := ord.ID()
boltdb.ordersUpdate(func(ob, archivedOB *bbolt.Bucket) error {
archivedOB.Bucket(oid[:]).Put(updateTimeKey, uint64Bytes(uint64(ord.P.ClientTime.UnixMilli())))
return nil
})
return oid
}
for i := 0; i < archiveSizeLimit*2; i++ {
addOrder(0)
Expand Down

0 comments on commit 43e8f54

Please sign in to comment.