-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
optimise pin update command #4348
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,27 +65,34 @@ type diffpair struct { | |
// getLinkDiff returns a changeset between nodes 'a' and 'b'. Currently does | ||
// not log deletions as our usecase doesnt call for this. | ||
func getLinkDiff(a, b node.Node) []diffpair { | ||
have := make(map[string]*node.Link) | ||
names := make(map[string]*node.Link) | ||
ina := make(map[string]*node.Link) | ||
inb := make(map[string]*node.Link) | ||
var aonly []*cid.Cid | ||
for _, l := range b.Links() { | ||
inb[l.Cid.KeyString()] = l | ||
} | ||
for _, l := range a.Links() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will be faster to just call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
have[l.Cid.KeyString()] = l | ||
names[l.Name] = l | ||
ina[l.Cid.KeyString()] = l | ||
if inb[l.Cid.KeyString()] == nil { | ||
aonly = append(aonly, l.Cid) | ||
} | ||
} | ||
|
||
var out []diffpair | ||
var aindex = 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can just say |
||
|
||
for _, l := range b.Links() { | ||
if have[l.Cid.KeyString()] != nil { | ||
if ina[l.Cid.KeyString()] != nil { | ||
continue | ||
} | ||
|
||
match, ok := names[l.Name] | ||
if !ok { | ||
if aindex < len(aonly) { | ||
out = append(out, diffpair{bef: aonly[aindex], aft: l.Cid}) | ||
aindex++ | ||
} else { | ||
out = append(out, diffpair{aft: l.Cid}) | ||
continue | ||
} | ||
|
||
out = append(out, diffpair{bef: match.Cid, aft: l.Cid}) | ||
} | ||
return out | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks right. The
Name
property of links is a protonode thing (that needs to die).