Skip to content

Commit

Permalink
gateway/blocks-backend: GetBlock should not perform IPLD decoding ipf…
Browse files Browse the repository at this point in the history
  • Loading branch information
gsergey418alt committed Feb 14, 2025
1 parent 24b6bc3 commit a33795b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions gateway/backend_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/ipld/go-car/v2/storage"
dagpb "github.com/ipld/go-codec-dagpb"
"github.com/ipld/go-ipld-prime"

// Ensure basic codecs are registered.
_ "github.com/ipld/go-ipld-prime/codec/cbor"
_ "github.com/ipld/go-ipld-prime/codec/dagcbor"
Expand Down Expand Up @@ -210,12 +211,25 @@ func (bb *BlocksBackend) GetAll(ctx context.Context, path path.ImmutablePath) (C
}

func (bb *BlocksBackend) GetBlock(ctx context.Context, path path.ImmutablePath) (ContentPathMetadata, files.File, error) {
md, nd, err := bb.getNode(ctx, path)
roots, lastSeg, remainder, err := bb.getPathRoots(ctx, path)
if err != nil {
return ContentPathMetadata{}, nil, err
}

md := ContentPathMetadata{
PathSegmentRoots: roots,
LastSegment: lastSeg,
LastSegmentRemainder: remainder,
}

lastRoot := lastSeg.RootCid()

b, err := bb.blockService.GetBlock(ctx, lastRoot)
if err != nil {
return md, nil, err
}

return md, files.NewBytesFile(nd.RawData()), nil
return md, files.NewBytesFile(b.RawData()), nil
}

func (bb *BlocksBackend) Head(ctx context.Context, path path.ImmutablePath) (ContentPathMetadata, *HeadResponse, error) {
Expand Down

0 comments on commit a33795b

Please sign in to comment.