Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-ld-format
Commits
c96181f0
Unverified
Commit
c96181f0
authored
Oct 26, 2018
by
Hector Sanjuan
Committed by
GitHub
Oct 26, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #46 from ipfs/fix/batchds
Make Batch implement a NodeAdder interface
parents
2f245e49
4f06ec02
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
15 deletions
+27
-15
.gx/lastpubver
.gx/lastpubver
+1
-1
batch.go
batch.go
+11
-3
batch_test.go
batch_test.go
+1
-1
merkledag.go
merkledag.go
+13
-9
package.json
package.json
+1
-1
No files found.
.gx/lastpubver
View file @
c96181f0
0.
6
.0: Qmd
DXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL
0.
7
.0: Qmd
VNBLt7RMYnZwqBQJeexmSbTEDzERjBQUfs5McuPfEtB
batch.go
View file @
c96181f0
...
...
@@ -104,7 +104,13 @@ func (t *Batch) asyncCommit() {
}
// Add adds a node to the batch and commits the batch if necessary.
func
(
t
*
Batch
)
Add
(
nd
Node
)
error
{
func
(
t
*
Batch
)
Add
(
ctx
context
.
Context
,
nd
Node
)
error
{
return
t
.
AddMany
(
ctx
,
[]
Node
{
nd
})
}
// Add many calls Add for every given Node, thus batching and
// commiting them as needed.
func
(
t
*
Batch
)
AddMany
(
ctx
context
.
Context
,
nodes
[]
Node
)
error
{
if
t
.
err
!=
nil
{
return
t
.
err
}
...
...
@@ -115,8 +121,10 @@ func (t *Batch) Add(nd Node) error {
return
t
.
err
}
t
.
nodes
=
append
(
t
.
nodes
,
nd
)
t
.
size
+=
len
(
nd
.
RawData
())
t
.
nodes
=
append
(
t
.
nodes
,
nodes
...
)
for
_
,
nd
:=
range
nodes
{
t
.
size
+=
len
(
nd
.
RawData
())
}
if
t
.
size
>
t
.
opts
.
maxSize
||
len
(
t
.
nodes
)
>
t
.
opts
.
maxNodes
{
t
.
asyncCommit
()
...
...
batch_test.go
View file @
c96181f0
...
...
@@ -86,7 +86,7 @@ func TestBatch(t *testing.T) {
// It would be great if we could use *many* different nodes here
// but we can't add any dependencies and I don't feel like adding
// any more testing code.
if
err
:=
b
.
Add
(
new
(
EmptyNode
));
err
!=
nil
{
if
err
:=
b
.
Add
(
ctx
,
new
(
EmptyNode
));
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
...
...
merkledag.go
View file @
c96181f0
...
...
@@ -26,6 +26,18 @@ type NodeGetter interface {
GetMany
(
context
.
Context
,
[]
cid
.
Cid
)
<-
chan
*
NodeOption
}
// NodeAdder adds nodes to a DAG.
type
NodeAdder
interface
{
// Add adds a node to this DAG.
Add
(
context
.
Context
,
Node
)
error
// AddMany adds many nodes to this DAG.
//
// Consider using the Batch NodeAdder (`NewBatch`) if you make
// extensive use of this function.
AddMany
(
context
.
Context
,
[]
Node
)
error
}
// NodeGetters can optionally implement this interface to make finding linked
// objects faster.
type
LinkGetter
interface
{
...
...
@@ -41,21 +53,13 @@ type LinkGetter interface {
// DAGService is an IPFS Merkle DAG service.
type
DAGService
interface
{
NodeGetter
// Add adds a node to this DAG.
Add
(
context
.
Context
,
Node
)
error
NodeAdder
// Remove removes a node from this DAG.
//
// Remove returns no error if the requested node is not present in this DAG.
Remove
(
context
.
Context
,
cid
.
Cid
)
error
// AddMany adds many nodes to this DAG.
//
// Consider using NewBatch instead of calling this directly if you need
// to add an unbounded number of nodes to avoid buffering too much.
AddMany
(
context
.
Context
,
[]
Node
)
error
// RemoveMany removes many nodes from this DAG.
//
// It returns success even if the nodes were not present in the DAG.
...
...
package.json
View file @
c96181f0
...
...
@@ -31,6 +31,6 @@
"license"
:
""
,
"name"
:
"go-ipld-format"
,
"releaseCmd"
:
"git commit -a -m
\"
gx publish $VERSION
\"
"
,
"version"
:
"0.
6
.0"
"version"
:
"0.
7
.0"
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment