From 4e26b9d2adf2de88d78c38b1a7b4d20d45f73d1c Mon Sep 17 00:00:00 2001 From: c9s Date: Tue, 12 Dec 2023 18:25:09 +0800 Subject: [PATCH] core: pull out cool trade period to a constant --- pkg/core/tradestore.go | 3 ++- pkg/core/tradestore_test.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/core/tradestore.go b/pkg/core/tradestore.go index 340e3df15..f1acdb244 100644 --- a/pkg/core/tradestore.go +++ b/pkg/core/tradestore.go @@ -10,6 +10,7 @@ import ( ) const TradeExpiryTime = 3 * time.Hour +const CoolTradePeriod = 1 * time.Hour const MaximumTradeStoreSize = 1_000 type TradeStore struct { @@ -139,7 +140,7 @@ func (s *TradeStore) Prune(curTime time.Time) { func (s *TradeStore) isCoolTrade(trade types.Trade) bool { // if the duration between the current trade and the last trade is over 1 hour, we call it "cool trade" - return !s.lastTradeTime.IsZero() && time.Time(trade.Time).Sub(s.lastTradeTime) > time.Hour + return !s.lastTradeTime.IsZero() && time.Time(trade.Time).Sub(s.lastTradeTime) > CoolTradePeriod } func (s *TradeStore) exceededMaximumTradeStoreSize() bool { diff --git a/pkg/core/tradestore_test.go b/pkg/core/tradestore_test.go index 431572ab4..c820a2a02 100644 --- a/pkg/core/tradestore_test.go +++ b/pkg/core/tradestore_test.go @@ -30,7 +30,7 @@ func TestTradeStore_Prune(t *testing.T) { store := NewTradeStore() store.Add( types.Trade{ID: 1, Time: types.Time(now.Add(-25 * time.Hour))}, - types.Trade{ID: 2, Time: types.Time(now.Add(-23 * time.Hour))}, + types.Trade{ID: 2, Time: types.Time(now.Add(-2 * time.Hour))}, types.Trade{ID: 3, Time: types.Time(now.Add(-2 * time.Minute))}, types.Trade{ID: 4, Time: types.Time(now.Add(-1 * time.Minute))}, )