Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1bb4530

Browse files
committedJul 10, 2015
dont use searchset for indirect pin checking
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
1 parent c2fc8bc commit 1bb4530

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed
 

‎pin/pin.go

+15-25
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,16 @@ func (p *pinner) isPinned(k key.Key) (string, bool, error) {
177177
}
178178

179179
for _, rk := range p.recursePin.GetKeys() {
180-
ss := &searchSet{target: k}
181-
182180
rnd, err := p.dserv.Get(context.Background(), rk)
183181
if err != nil {
184182
return "", false, err
185183
}
186184

187-
err = mdag.EnumerateChildren(context.Background(), p.dserv, rnd, ss)
185+
has, err := hasChild(p.dserv, rnd, k)
188186
if err != nil {
189187
return "", false, err
190188
}
191-
192-
if ss.found {
189+
if has {
193190
return rk.B58String(), true, nil
194191
}
195192
}
@@ -350,26 +347,19 @@ func (p *pinner) PinWithMode(k key.Key, mode PinMode) {
350347
}
351348
}
352349

353-
// searchSet implements key.KeySet in
354-
type searchSet struct {
355-
target key.Key
356-
found bool
357-
}
358-
359-
func (ss *searchSet) Add(k key.Key) {
360-
if ss.target == k {
361-
ss.found = true
362-
}
363-
}
350+
func hasChild(ds mdag.DAGService, root *mdag.Node, child key.Key) (bool, error) {
351+
for _, lnk := range root.Links {
352+
k := key.Key(lnk.Hash)
353+
if k == child {
354+
return true, nil
355+
}
364356

365-
func (ss *searchSet) Has(k key.Key) bool {
366-
// returning true to all Has queries will cause EnumerateChildren to return
367-
// almost immediately
368-
return ss.found
369-
}
357+
nd, err := ds.Get(context.Background(), k)
358+
if err != nil {
359+
return false, err
360+
}
370361

371-
func (ss *searchSet) Keys() []key.Key {
372-
return nil
362+
return hasChild(ds, nd, child)
363+
}
364+
return false, nil
373365
}
374-
375-
func (ss *searchSet) Remove(key.Key) {}

0 commit comments

Comments
 (0)
Please sign in to comment.