Skip to content

Commit 04b7a8f

Browse files
feat(ObjectApi.LinksAsync): make faster
If the CID is not a dag-pb, then immediately return an empty list. This avoids reading the CID and catching an exception.
1 parent 3e16510 commit 04b7a8f

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/CoreApi/ObjectApi.cs

+5-7
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,14 @@ public ObjectApi(IpfsEngine ipfs)
5050

5151
public async Task<IEnumerable<IMerkleLink>> LinksAsync(Cid id, CancellationToken cancel = default(CancellationToken))
5252
{
53-
var block = await ipfs.Block.GetAsync(id, cancel).ConfigureAwait(false);
54-
try
55-
{
56-
var node = new DagNode(block.DataStream);
57-
return node.Links;
58-
}
59-
catch
53+
if (id.ContentType != "dag-pb")
6054
{
6155
return Enumerable.Empty<IMerkleLink>();
6256
}
57+
58+
var block = await ipfs.Block.GetAsync(id, cancel).ConfigureAwait(false);
59+
var node = new DagNode(block.DataStream);
60+
return node.Links;
6361
}
6462

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

0 commit comments

Comments
 (0)