Slightly optimizes core.ResolveToKey().
This is done by skipping the step of resolving the final segment in the path to a DAG node; instead preferring to look at the second-to-last segmenet's links. License: MIT Signed-off-by: Stephen Whitmore <noffle@ipfs.io>
Stephen Whitmore committed
Jan 24, 2016 at 23:31 UTC
9745704f5fc1c6d59e0c73716e243d1dbbe6f0c2
2 files changed
+13
-5
core/pathresolver.go
+11
-5
@@ -71,16 +71,22 @@ func ResolveToKey(ctx context.Context, n *IpfsNode, p path.Path) (key.Key, error
71
return key.B58KeyDecode(p.Segments()[1]), nil
72
}
73
74
- // Fall back onto regular dagnode resolution.
75
- dagnode, err := Resolve(ctx, n, p)
74
+ // Fall back onto regular dagnode resolution. Retrieve the second-to-last
75
+ // segment of the path and resolve its link to the last segment.
76
+ head, tail, err := p.PopLastSegment()
77
+ if err != nil {
78
+ return key.Key(""), err
79
+ }
80
+ dagnode, err := Resolve(ctx, n, head)
81
if err != nil {
82
return key.Key(""), err
83
}
84
80
- // Extract and return the node's key.
81
- k, err := dagnode.Key()
85
+ // Extract and return the key of the link to the target dag node.
86
+ link, err := dagnode.GetNodeLink(tail)
87
if err != nil {
88
return key.Key(""), err
89
}
85
- return k, nil
90
+
91
+ return key.Key(link.Hash), nil
92
}
test/sharness/t0081-repo-pinning.sh
+2
@@ -283,6 +283,8 @@ FICTIONAL_HASH="QmXV4f9v8a56MxWKBhP3ETsz4EaafudU1cKfPaaJnenc48"
283
test_launch_ipfs_daemon
284
test_expect_success "test unpinning a hash that's not pinned" "
285
test_expect_code 1 ipfs pin rm $FICTIONAL_HASH --timeout=5s
286
+ test_expect_code 1 ipfs pin rm $FICTIONAL_HASH/a --timeout=5s
287
+ test_expect_code 1 ipfs pin rm $FICTIONAL_HASH/a/b --timeout=5s
288
"
289
test_kill_ipfs_daemon
290