Skip to content

Commit

Permalink
Prefer CollectRows to ForEachRow even tho it takes more lines
Browse files Browse the repository at this point in the history
  • Loading branch information
serprex committed Nov 4, 2024
1 parent 702f1d9 commit 7150848
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions flow/cmd/mirror_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,15 @@ func (h *FlowRequestHandler) CDCGraph(ctx context.Context, req *protos.GraphRequ
if err != nil {
return nil, err
}
var data []*protos.GraphResponseItem
var t time.Time
var r int64
if _, err := pgx.ForEachRow(rows, []any{&t, &r}, func() error {
data = append(data, &protos.GraphResponseItem{Time: float64(t.UnixMilli()), Rows: float64(r)})
return nil
}); err != nil {
data, err := pgx.CollectRows(rows, func(row pgx.CollectableRow) (*protos.GraphResponseItem, error) {
var t time.Time
var r int64
if err := row.Scan(&t, &r); err != nil {
return nil, err
}
return &protos.GraphResponseItem{Time: float64(t.UnixMilli()), Rows: float64(r)}, nil
})
if err != nil {
return nil, err
}

Expand Down

0 comments on commit 7150848

Please sign in to comment.