Skip to content

Commit

Permalink
chore: remove unused url params
Browse files Browse the repository at this point in the history
Closes #80
  • Loading branch information
lidel committed Jun 2, 2023
1 parent 01a1589 commit 40dfcf0
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions lib/graph_gateway.go
Expand Up @@ -470,11 +470,11 @@ func (api *GraphGateway) Get(ctx context.Context, path gateway.ImmutablePath, by
rangeCount := len(byteRanges)
api.metrics.carParamsMetric.With(prometheus.Labels{"dagScope": "entity", "entityRanges": strconv.Itoa(rangeCount)}).Inc()

// TODO: remove &bytes= &depth= and &car-scope from all CAR request after transition is done:
// https://github.com/ipfs/bifrost-gateway/issues/80
carParams := "?format=car&dag-scope=entity&car-scope=file&depth=1"
// IPIP-402
carParams := "?format=car&dag-scope=entity"

Check warning on line 474 in lib/graph_gateway.go

View check run for this annotation

Codecov / codecov/patch

lib/graph_gateway.go#L473-L474

Added lines #L473 - L474 were not covered by tests

// fetch CAR with &bytes= to get minimal set of blocks for the request
// If request was HTTP Range Request fetch CAR with entity-bytes=from:to to
// get minimal set of blocks

Check warning on line 477 in lib/graph_gateway.go

View check run for this annotation

Codecov / codecov/patch

lib/graph_gateway.go#L476-L477

Added lines #L476 - L477 were not covered by tests
// Note: majority of requests have 0 or max 1 ranges. if there are more ranges than one,
// that is a niche edge cache we don't prefetch as CAR and use fallback blockstore instead.
if rangeCount > 0 {
Expand All @@ -496,17 +496,7 @@ func (api *GraphGateway) Get(ctx context.Context, path gateway.ImmutablePath, by
} else {
bytesBuilder.WriteString("*")
}

// TODO: &bytes= is present only for transition reasons, remove below block after https://github.com/ipfs/bifrost-gateway/issues/80 is done
if strings.HasSuffix(carParams, "&depth=1") {
parts := strings.Split(bytesBuilder.String(), "=")
value := parts[1]
bytesBuilder.WriteString("&bytes=")
bytesBuilder.WriteString(value)
}

carParams += bytesBuilder.String()

}

blkgw, closeFn, err := api.loadRequestIntoSharedBlockstoreAndBlocksGateway(ctx, path.String()+carParams)
Expand All @@ -525,7 +515,7 @@ func (api *GraphGateway) Get(ctx context.Context, path gateway.ImmutablePath, by

func (api *GraphGateway) GetAll(ctx context.Context, path gateway.ImmutablePath) (gateway.ContentPathMetadata, files.Node, error) {
api.metrics.carParamsMetric.With(prometheus.Labels{"dagScope": "all", "entityRanges": "0"}).Inc()
blkgw, closeFn, err := api.loadRequestIntoSharedBlockstoreAndBlocksGateway(ctx, path.String()+"?format=car&dag-scope=all&car-scope=all&depth=all")
blkgw, closeFn, err := api.loadRequestIntoSharedBlockstoreAndBlocksGateway(ctx, path.String()+"?format=car&dag-scope=all")

Check warning on line 518 in lib/graph_gateway.go

View check run for this annotation

Codecov / codecov/patch

lib/graph_gateway.go#L518

Added line #L518 was not covered by tests
if err != nil {
return gateway.ContentPathMetadata{}, nil, err
}
Expand All @@ -543,7 +533,7 @@ func (api *GraphGateway) GetAll(ctx context.Context, path gateway.ImmutablePath)
func (api *GraphGateway) GetBlock(ctx context.Context, path gateway.ImmutablePath) (gateway.ContentPathMetadata, files.File, error) {
api.metrics.carParamsMetric.With(prometheus.Labels{"dagScope": "block", "entityRanges": "0"}).Inc()
// TODO: if path is `/ipfs/cid`, we should use ?format=raw
blkgw, closeFn, err := api.loadRequestIntoSharedBlockstoreAndBlocksGateway(ctx, path.String()+"?format=car&dag-scope=block&car-scope=block&depth=0")
blkgw, closeFn, err := api.loadRequestIntoSharedBlockstoreAndBlocksGateway(ctx, path.String()+"?format=car&dag-scope=block")

Check warning on line 536 in lib/graph_gateway.go

View check run for this annotation

Codecov / codecov/patch

lib/graph_gateway.go#L536

Added line #L536 was not covered by tests
if err != nil {
return gateway.ContentPathMetadata{}, nil, err
}
Expand All @@ -565,7 +555,7 @@ func (api *GraphGateway) Head(ctx context.Context, path gateway.ImmutablePath) (
api.metrics.bytesRangeStartMetric.Observe(0)
api.metrics.bytesRangeSizeMetric.Observe(1024)

blkgw, closeFn, err := api.loadRequestIntoSharedBlockstoreAndBlocksGateway(ctx, path.String()+"?format=car&dag-scope=entity&entity-bytes=0:1023&car-scope=file&depth=1&bytes=0:1023")
blkgw, closeFn, err := api.loadRequestIntoSharedBlockstoreAndBlocksGateway(ctx, path.String()+"?format=car&dag-scope=entity&entity-bytes=0:1023")

Check warning on line 558 in lib/graph_gateway.go

View check run for this annotation

Codecov / codecov/patch

lib/graph_gateway.go#L558

Added line #L558 was not covered by tests

if err != nil {
return gateway.ContentPathMetadata{}, nil, err
Expand All @@ -583,7 +573,7 @@ func (api *GraphGateway) Head(ctx context.Context, path gateway.ImmutablePath) (

func (api *GraphGateway) ResolvePath(ctx context.Context, path gateway.ImmutablePath) (gateway.ContentPathMetadata, error) {
api.metrics.carParamsMetric.With(prometheus.Labels{"dagScope": "block", "entityRanges": "0"}).Inc()
blkgw, closeFn, err := api.loadRequestIntoSharedBlockstoreAndBlocksGateway(ctx, path.String()+"?format=car&dag-scope=block&car-scope=block&depth=0")
blkgw, closeFn, err := api.loadRequestIntoSharedBlockstoreAndBlocksGateway(ctx, path.String()+"?format=car&dag-scope=block")

Check warning on line 576 in lib/graph_gateway.go

View check run for this annotation

Codecov / codecov/patch

lib/graph_gateway.go#L576

Added line #L576 was not covered by tests
if err != nil {
return gateway.ContentPathMetadata{}, err
}
Expand All @@ -593,7 +583,7 @@ func (api *GraphGateway) ResolvePath(ctx context.Context, path gateway.Immutable

func (api *GraphGateway) GetCAR(ctx context.Context, path gateway.ImmutablePath) (gateway.ContentPathMetadata, io.ReadCloser, <-chan error, error) {
api.metrics.carParamsMetric.With(prometheus.Labels{"dagScope": "all", "entityRanges": "0"}).Inc()
blkgw, closeFn, err := api.loadRequestIntoSharedBlockstoreAndBlocksGateway(ctx, path.String()+"?format=car&dag-scope=all&car-scope=all&depth=all")
blkgw, closeFn, err := api.loadRequestIntoSharedBlockstoreAndBlocksGateway(ctx, path.String()+"?format=car&dag-scope=all")

Check warning on line 586 in lib/graph_gateway.go

View check run for this annotation

Codecov / codecov/patch

lib/graph_gateway.go#L586

Added line #L586 was not covered by tests
if err != nil {
return gateway.ContentPathMetadata{}, nil, nil, err
}
Expand Down

0 comments on commit 40dfcf0

Please sign in to comment.