Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Batch.ResetRetained #133

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions batch.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package bond

import (
"encoding/binary"
"fmt"
"io"

Expand All @@ -24,7 +23,6 @@ type Batch interface {
Len() int
Empty() bool
Reset()
ResetRetained()

Getter
Setter
Expand Down Expand Up @@ -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)
}
Expand Down
45 changes: 0 additions & 45 deletions batch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Loading