From 508e3c3a81781f9ddb31684e693c67eded607ca7 Mon Sep 17 00:00:00 2001 From: marcello33 Date: Fri, 11 Aug 2023 11:44:47 +0200 Subject: [PATCH 1/2] dev: chg: avoid greedy allocation on graphql blocks call --- graphql/graphql.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/graphql/graphql.go b/graphql/graphql.go index 492e99db4d..99b495aef4 100644 --- a/graphql/graphql.go +++ b/graphql/graphql.go @@ -1350,7 +1350,7 @@ func (r *Resolver) Blocks(ctx context.Context, args struct { return []*Block{}, nil } - ret := make([]*Block, 0, to-from+1) + var ret []*Block for i := from; i <= to; i++ { numberOrHash := rpc.BlockNumberOrHashWithNumber(i) @@ -1370,6 +1370,9 @@ func (r *Resolver) Blocks(ctx context.Context, args struct { } ret = append(ret, block) + if err := ctx.Err(); err != nil { + return nil, err + } } return ret, nil From a4b469d37d57dc0d3cfc5c6796cc1d7a1beceb5a Mon Sep 17 00:00:00 2001 From: marcello33 Date: Fri, 11 Aug 2023 12:07:06 +0200 Subject: [PATCH 2/2] dev: fix: linter issues --- graphql/graphql.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/graphql/graphql.go b/graphql/graphql.go index 99b495aef4..9a668c517e 100644 --- a/graphql/graphql.go +++ b/graphql/graphql.go @@ -1350,6 +1350,7 @@ func (r *Resolver) Blocks(ctx context.Context, args struct { return []*Block{}, nil } + // nolint:prealloc var ret []*Block for i := from; i <= to; i++ { @@ -1370,6 +1371,7 @@ func (r *Resolver) Blocks(ctx context.Context, args struct { } ret = append(ret, block) + if err := ctx.Err(); err != nil { return nil, err }