graphql: dev: chg: avoid greedy allocation on graphql blocks call (#958)

* dev: chg: avoid greedy allocation on graphql blocks call

* dev: fix: linter issues
This commit is contained in:
marcello33 2023-08-11 14:37:11 +02:00 committed by GitHub
parent d4959497c8
commit b4cc1f65be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1350,7 +1350,8 @@ func (r *Resolver) Blocks(ctx context.Context, args struct {
return []*Block{}, nil
}
ret := make([]*Block, 0, to-from+1)
// nolint:prealloc
var ret []*Block
for i := from; i <= to; i++ {
numberOrHash := rpc.BlockNumberOrHashWithNumber(i)
@ -1370,6 +1371,10 @@ 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