Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coreapi/pin: Use CID's directly in maps instead of converting to string #5809

Merged
merged 1 commit into from
Nov 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions core/coreapi/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,24 +116,23 @@ func (n *badNode) Err() error {
}

func (api *PinAPI) Verify(ctx context.Context) (<-chan coreiface.PinStatus, error) {
visited := make(map[string]*pinStatus)
visited := make(map[cid.Cid]*pinStatus)
bs := api.node.Blocks.Blockstore()
DAG := merkledag.NewDAGService(bserv.New(bs, offline.Exchange(bs)))
getLinks := merkledag.GetLinksWithDAG(DAG)
recPins := api.node.Pinning.RecursiveKeys()

var checkPin func(root cid.Cid) *pinStatus
checkPin = func(root cid.Cid) *pinStatus {
key := root.String()
if status, ok := visited[key]; ok {
if status, ok := visited[root]; ok {
return status
}

links, err := getLinks(ctx, root)
if err != nil {
status := &pinStatus{ok: false, cid: root}
status.badNodes = []coreiface.BadPinNode{&badNode{path: coreiface.IpldPath(root), err: err}}
visited[key] = status
visited[root] = status
return status
}

Expand All @@ -146,7 +145,7 @@ func (api *PinAPI) Verify(ctx context.Context) (<-chan coreiface.PinStatus, erro
}
}

visited[key] = status
visited[root] = status
return status
}

Expand Down Expand Up @@ -176,11 +175,11 @@ func (p *pinInfo) Type() string {

func (api *PinAPI) pinLsAll(typeStr string, ctx context.Context) ([]coreiface.Pin, error) {

keys := make(map[string]*pinInfo)
keys := make(map[cid.Cid]*pinInfo)

AddToResultKeys := func(keyList []cid.Cid, typeStr string) {
for _, c := range keyList {
keys[c.String()] = &pinInfo{
keys[c] = &pinInfo{
pinType: typeStr,
path: coreiface.IpldPath(c),
}
Expand Down