Skip to content

Commit

Permalink
do in 1 loop
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Nov 20, 2024
1 parent fddcf4a commit 3821b43
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions share/shwap/p2p/bitswap/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,18 @@ func (g *Getter) GetSamples(
defer release()

err := Fetch(ctx, g.exchange, hdr.DAH, blks, WithStore(g.bstore), WithFetcher(ses))
if err != nil {
// handle partial fetches
var fetched int
smpls := make([]shwap.Sample, len(blks))
for i, blk := range blks {
if smpl := blk.(*SampleBlock).Container; !smpl.IsEmpty() {
smpls[i] = smpl
fetched++
}

var fetched int
smpls := make([]shwap.Sample, len(blks))
for i, blk := range blks {
c := blk.(*SampleBlock).Container
if !c.IsEmpty() {
fetched++
smpls[i] = c
}
}

if err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, "Fetch")
if fetched > 0 {
Expand All @@ -129,12 +130,6 @@ func (g *Getter) GetSamples(
return nil, err
}

smpls := make([]shwap.Sample, len(blks))
for i, blk := range blks {
c := blk.(*SampleBlock).Container
smpls[i] = c
}

span.SetStatus(codes.Ok, "")
return smpls, nil
}
Expand Down

0 comments on commit 3821b43

Please sign in to comment.