Skip to content

Commit

Permalink
Add batching when Adding.
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Hector Sanjuan <[email protected]>
  • Loading branch information
hsanjuan committed Oct 29, 2018
1 parent 1e76e5f commit 9fde50b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/commands/dag/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ into an object of the specified format.
}

for _, nd := range nds {
err := b.Add(nd)
err := b.Add(req.Context, nd)
if err != nil {
return err
}
Expand Down
9 changes: 8 additions & 1 deletion core/coreunix/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ type Object struct {

// NewAdder Returns a new Adder used for a file add operation.
func NewAdder(ctx context.Context, p pin.Pinner, bs bstore.GCBlockstore, ds ipld.DAGService) (*Adder, error) {
bufferedDS := ipld.NewBufferedDAG(ctx, ds)

return &Adder{
ctx: ctx,
pinning: p,
blockstore: bs,
dagService: ds,
bufferedDS: bufferedDS,
Progress: false,
Hidden: true,
Pin: true,
Expand All @@ -69,6 +72,7 @@ type Adder struct {
pinning pin.Pinner
blockstore bstore.GCBlockstore
dagService ipld.DAGService
bufferedDS *ipld.BufferedDAG
Out chan<- interface{}
Progress bool
Hidden bool
Expand Down Expand Up @@ -114,8 +118,11 @@ func (adder *Adder) add(reader io.Reader) (ipld.Node, error) {
return nil, err
}

// Make sure all added nodes are written when done.
defer adder.bufferedDS.Commit()

params := ihelper.DagBuilderParams{
Dagserv: adder.dagService,
Dagserv: adder.bufferedDS,
RawLeaves: adder.RawLeaves,
Maxlinks: ihelper.DefaultLinksPerBlock,
NoCopy: adder.NoCopy,
Expand Down

0 comments on commit 9fde50b

Please sign in to comment.