mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-01 22:37:51 +08:00
optimise pin update command
This handles merkle links that aren't named. And improves the Peergos usage from worst case 30s to ~20ms License: MIT Signed-off-by: Ian Preston <ianopolous@protonmail.com>
This commit is contained in:
parent
0ce9c2e0b5
commit
885de4f352
@ -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() {
|
||||
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
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user