Skip to content

Commit c2987ea

Browse files
authored
fix: speed on ReadN (#279)
* allocate memory on tests * similar behavior as before * fix performance * fix lint * remove comments
1 parent d52fadf commit c2987ea

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

source/logrepl/cdc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (i *CDCIterator) NextN(ctx context.Context, n int) ([]opencdc.Record, error
124124
return nil, fmt.Errorf("n must be greater than 0, got %d", n)
125125
}
126126

127-
recs := make([]opencdc.Record, 0, n)
127+
var recs []opencdc.Record
128128

129129
// Block until at least one record is received or context is canceled
130130
select {

source/logrepl/cdc_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ func TestCDCIterator_NextN(t *testing.T) {
510510
}
511511

512512
// Will keep calling NextN until all records are received
513-
var records []opencdc.Record
513+
records := make([]opencdc.Record, 0, 2)
514514
for len(records) < 2 {
515515
recordsTmp, err := i.NextN(ctx, 5)
516516
is.NoErr(err)

source/logrepl/combined.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func (c *CombinedIterator) NextN(ctx context.Context, n int) ([]opencdc.Record,
131131
}
132132

133133
sdk.Logger(ctx).Debug().Msg("Snapshot completed, switching to CDC mode")
134-
return c.activeIterator.NextN(ctx, n)
134+
return c.NextN(ctx, n)
135135
}
136136
return records, nil
137137
}

source/logrepl/combined_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ func TestCombinedIterator_NextN(t *testing.T) {
289289
is.NoErr(err)
290290

291291
// Request 2 records in CDC mode
292-
var records []opencdc.Record
292+
records := make([]opencdc.Record, 0, 2)
293293
var retries int
294294
maxRetries := 10
295295
for retries < maxRetries {

0 commit comments

Comments
 (0)