Skip to content

Commit

Permalink
feat(ObjectApi.LinksAsync): make faster
Browse files Browse the repository at this point in the history
If the CID is not a dag-pb, then immediately return an empty list.  This
avoids reading the CID and catching an exception.
  • Loading branch information
richardschneider committed Aug 15, 2019
1 parent 3e16510 commit 04b7a8f
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/CoreApi/ObjectApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,14 @@ public async Task<DagNode> GetAsync(Cid id, CancellationToken cancel = default(C

public async Task<IEnumerable<IMerkleLink>> LinksAsync(Cid id, CancellationToken cancel = default(CancellationToken))
{
var block = await ipfs.Block.GetAsync(id, cancel).ConfigureAwait(false);
try
{
var node = new DagNode(block.DataStream);
return node.Links;
}
catch
if (id.ContentType != "dag-pb")
{
return Enumerable.Empty<IMerkleLink>();
}

var block = await ipfs.Block.GetAsync(id, cancel).ConfigureAwait(false);
var node = new DagNode(block.DataStream);
return node.Links;
}

public Task<DagNode> NewAsync(string template = null, CancellationToken cancel = default(CancellationToken))
Expand Down

0 comments on commit 04b7a8f

Please sign in to comment.