Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
fix: single byte range prefetch (#73)
Browse files Browse the repository at this point in the history
Seems there is no agreement on supporting more than one byte range.
This will only prefetch the first range as CAR, and use block-by-block
for remaining ones.

In practice, we don't expect to see more than a single range in the real
world, video seeking creates a single one etc.
  • Loading branch information
lidel authored Apr 3, 2023
1 parent bfe2e6f commit e68f6ca
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions lib/graph_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,18 +345,16 @@ func (api *GraphGateway) Get(ctx context.Context, path gateway.ImmutablePath, by
carParams := "?format=car&depth=1"

// fetch CAR with &bytes= to get minimal set of blocks for the request
// 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 {
bytesBuilder := strings.Builder{}
bytesBuilder.WriteString("&bytes=")
for i, r := range byteRanges {
bytesBuilder.WriteString(strconv.FormatUint(r.From, 10))
bytesBuilder.WriteString("-")
if r.To != nil {
bytesBuilder.WriteString(strconv.FormatInt(*r.To, 10))
}
if i != rangeCount-1 {
bytesBuilder.WriteString(",")
}
r := byteRanges[0]
bytesBuilder.WriteString(strconv.FormatUint(r.From, 10))
bytesBuilder.WriteString(":")
if r.To != nil {
bytesBuilder.WriteString(strconv.FormatInt(*r.To, 10))
}
carParams += bytesBuilder.String()
}
Expand Down

0 comments on commit e68f6ca

Please sign in to comment.