@@ -177,19 +177,16 @@ func (p *pinner) isPinned(k key.Key) (string, bool, error) {
177
177
}
178
178
179
179
for _ , rk := range p .recursePin .GetKeys () {
180
- ss := & searchSet {target : k }
181
-
182
180
rnd , err := p .dserv .Get (context .Background (), rk )
183
181
if err != nil {
184
182
return "" , false , err
185
183
}
186
184
187
- err = mdag . EnumerateChildren ( context . Background (), p .dserv , rnd , ss )
185
+ has , err := hasChild ( p .dserv , rnd , k )
188
186
if err != nil {
189
187
return "" , false , err
190
188
}
191
-
192
- if ss .found {
189
+ if has {
193
190
return rk .B58String (), true , nil
194
191
}
195
192
}
@@ -350,26 +347,19 @@ func (p *pinner) PinWithMode(k key.Key, mode PinMode) {
350
347
}
351
348
}
352
349
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
+ }
364
356
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
+ }
370
361
371
- func (ss * searchSet ) Keys () []key.Key {
372
- return nil
362
+ return hasChild (ds , nd , child )
363
+ }
364
+ return false , nil
373
365
}
374
-
375
- func (ss * searchSet ) Remove (key.Key ) {}
0 commit comments