mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-22 02:47:48 +08:00
improves memory usage of add
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
parent
b6f28dad1b
commit
d8ee7dffc3
@ -317,7 +317,7 @@ func (params *Adder) addDir(dir files.File) (*merkledag.Node, error) {
|
||||
|
||||
name := gopath.Base(file.FileName())
|
||||
|
||||
if err := tree.AddNodeLink(name, node); err != nil {
|
||||
if err := tree.AddNodeLinkClean(name, node); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ type DAGService interface {
|
||||
AddRecursive(*Node) error
|
||||
Get(context.Context, key.Key) (*Node, error)
|
||||
Remove(*Node) error
|
||||
RemoveRecursive(*Node) error
|
||||
|
||||
// GetDAG returns, in order, all the single leve child
|
||||
// nodes of the passed in node.
|
||||
@ -107,10 +108,10 @@ func (n *dagService) Get(ctx context.Context, k key.Key) (*Node, error) {
|
||||
}
|
||||
|
||||
// Remove deletes the given node and all of its children from the BlockService
|
||||
func (n *dagService) Remove(nd *Node) error {
|
||||
func (n *dagService) RemoveRecursive(nd *Node) error {
|
||||
for _, l := range nd.Links {
|
||||
if l.Node != nil {
|
||||
n.Remove(l.Node)
|
||||
n.RemoveRecursive(l.Node)
|
||||
}
|
||||
}
|
||||
k, err := nd.Key()
|
||||
@ -120,6 +121,14 @@ func (n *dagService) Remove(nd *Node) error {
|
||||
return n.Blocks.DeleteBlock(k)
|
||||
}
|
||||
|
||||
func (n *dagService) Remove(nd *Node) error {
|
||||
k, err := nd.Key()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return n.Blocks.DeleteBlock(k)
|
||||
}
|
||||
|
||||
// FetchGraph fetches all nodes that are children of the given node
|
||||
func FetchGraph(ctx context.Context, root *Node, serv DAGService) error {
|
||||
return EnumerateChildrenAsync(ctx, serv, root, key.NewKeySet())
|
||||
|
||||
@ -40,6 +40,8 @@ func addLink(ctx context.Context, ds dag.DAGService, root *dag.Node, childname s
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_ = ds.Remove(root)
|
||||
|
||||
// ensure no link with that name already exists
|
||||
_ = root.RemoveNodeLink(childname) // ignore error, only option is ErrNotFound
|
||||
|
||||
@ -83,6 +85,8 @@ func insertNodeAtPath(ctx context.Context, ds dag.DAGService, root *dag.Node, pa
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_ = ds.Remove(root)
|
||||
|
||||
_ = root.RemoveNodeLink(path[0])
|
||||
err = root.AddNodeLinkClean(path[0], ndprime)
|
||||
if err != nil {
|
||||
@ -133,6 +137,8 @@ func rmLink(ctx context.Context, ds dag.DAGService, root *dag.Node, path []strin
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_ = ds.Remove(root)
|
||||
|
||||
_ = root.RemoveNodeLink(path[0])
|
||||
err = root.AddNodeLinkClean(path[0], nnode)
|
||||
if err != nil {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user