From 7150848a55dea017d8cff72df3197b5d0e404079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Dub=C3=A9?= Date: Fri, 1 Nov 2024 13:10:06 +0000 Subject: [PATCH] Prefer CollectRows to ForEachRow even tho it takes more lines --- flow/cmd/mirror_status.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/flow/cmd/mirror_status.go b/flow/cmd/mirror_status.go index d030d73fb..3eb24568f 100644 --- a/flow/cmd/mirror_status.go +++ b/flow/cmd/mirror_status.go @@ -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 }