From 324192b7e64fe4bda6875ce221b15815408a215e Mon Sep 17 00:00:00 2001 From: Marcin Gorzynski Date: Tue, 2 Apr 2024 10:29:22 +0200 Subject: [PATCH] rem Batch.ResetRetained --- batch.go | 21 --------------------- batch_test.go | 45 --------------------------------------------- 2 files changed, 66 deletions(-) diff --git a/batch.go b/batch.go index 8e61776..8aa62a4 100644 --- a/batch.go +++ b/batch.go @@ -1,7 +1,6 @@ package bond import ( - "encoding/binary" "fmt" "io" @@ -24,7 +23,6 @@ type Batch interface { Len() int Empty() bool Reset() - ResetRetained() Getter Setter @@ -71,25 +69,6 @@ func (b *_batch) Reset() { b.onClose = nil } -func (b *_batch) ResetRetained() { - data := b.Batch.Repr() - b.Batch.Reset() - if data != nil { - data = data[:12] // reset to header only - binary.LittleEndian.PutUint64(data[:8], 0) // put starting sequ num - binary.LittleEndian.PutUint32(data[8:12], 0) // put count data - - _ = b.Batch.SetRepr(data) // set data buffer - } - - b.id, _ = sequenceId.Next() - - b.onCommitCallbacks = nil - b.onCommittedCallbacks = nil - b.onErrorCallbacks = nil - b.onClose = nil -} - func (b *_batch) Get(key []byte, _ ...Batch) (data []byte, closer io.Closer, err error) { return b.Batch.Get(key) } diff --git a/batch_test.go b/batch_test.go index d5b4c40..258b459 100644 --- a/batch_test.go +++ b/batch_test.go @@ -43,48 +43,3 @@ func Test_Batch_Callbacks(t *testing.T) { require.NoError(t, err) assert.Equal(t, 2, counter) } - -func Test_Batch_ResetRetained(t *testing.T) { - db, t1, _, _, _ := setupDatabaseForQuery() - defer tearDownDatabase(db) - - batch := db.Batch() - defer func() { _ = batch.Close() }() - - var count int - var inserts []*TokenBalance - for i := 0; i < 10000; i++ { - inserts = append(inserts, &TokenBalance{ - ID: uint64(count), - AccountID: 4, - ContractAddress: "0x122442131373712864321876413274623814238164214631", - AccountAddress: "0x122442131373712864321876413274623814238164214631", - TokenID: 5, - Balance: 1, - }) - count++ - } - - err := t1.Insert(context.Background(), inserts, batch) - require.NoError(t, err) - - err = batch.Commit(Sync) - require.NoError(t, err) - - batch.ResetRetained() - - for _, tb := range inserts { - tb.Balance = 5 - } - - err = t1.Update(context.Background(), inserts, batch) - require.NoError(t, err) - - err = batch.Commit(Sync) - require.NoError(t, err) - - var tokenBalances []*TokenBalance - err = t1.Scan(context.Background(), &tokenBalances, false) - require.NoError(t, err) - assert.Equal(t, inserts, tokenBalances) -}