Skip to content

Commit 6f794d8

Browse files
fix(keystore): use new batch after commit #1154
1 parent 2e3cea1 commit 6f794d8

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

provider/keystore/keystore.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,11 @@ func empty(ctx context.Context, d ds.Batching, batchSize int) error {
303303
if err = batch.Commit(ctx); err != nil {
304304
return fmt.Errorf("cannot commit keystore updates: %w", err)
305305
}
306+
// Create a new batch after committing the previous one
307+
batch, err = d.Batch(ctx)
308+
if err != nil {
309+
return err
310+
}
306311
}
307312
if err != nil {
308313
return fmt.Errorf("cannot read query result from keystore: %w", err)
@@ -312,8 +317,10 @@ func empty(ctx context.Context, d ds.Batching, batchSize int) error {
312317
}
313318
writeCount++
314319
}
315-
if err = batch.Commit(ctx); err != nil {
316-
return fmt.Errorf("cannot commit keystore updates: %w", err)
320+
if writeCount > 0 {
321+
if err = batch.Commit(ctx); err != nil {
322+
return fmt.Errorf("cannot commit keystore updates: %w", err)
323+
}
317324
}
318325
if err = d.Sync(ctx, ds.NewKey("")); err != nil {
319326
return fmt.Errorf("cannot sync datastore: %w", err)

0 commit comments

Comments
 (0)