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-merkledag
Commits
d3cca0ac
Commit
d3cca0ac
authored
Apr 08, 2018
by
Whyrusleeping
Committed by
GitHub
Apr 08, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4888 from ipfs/fix/dedup-keys
dedup keys in GetMany
parents
823a0716
7d5c56b1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
0 deletions
+43
-0
merkledag.go
merkledag.go
+13
-0
merkledag_test.go
merkledag_test.go
+30
-0
No files found.
merkledag.go
View file @
d3cca0ac
...
@@ -201,7 +201,20 @@ func (n *dagService) GetMany(ctx context.Context, keys []*cid.Cid) <-chan *ipld.
...
@@ -201,7 +201,20 @@ func (n *dagService) GetMany(ctx context.Context, keys []*cid.Cid) <-chan *ipld.
return
getNodesFromBG
(
ctx
,
n
.
Blocks
,
keys
)
return
getNodesFromBG
(
ctx
,
n
.
Blocks
,
keys
)
}
}
func
dedupKeys
(
keys
[]
*
cid
.
Cid
)
[]
*
cid
.
Cid
{
set
:=
cid
.
NewSet
()
for
_
,
c
:=
range
keys
{
set
.
Add
(
c
)
}
if
set
.
Len
()
==
len
(
keys
)
{
return
keys
}
return
set
.
Keys
()
}
func
getNodesFromBG
(
ctx
context
.
Context
,
bs
bserv
.
BlockGetter
,
keys
[]
*
cid
.
Cid
)
<-
chan
*
ipld
.
NodeOption
{
func
getNodesFromBG
(
ctx
context
.
Context
,
bs
bserv
.
BlockGetter
,
keys
[]
*
cid
.
Cid
)
<-
chan
*
ipld
.
NodeOption
{
keys
=
dedupKeys
(
keys
)
out
:=
make
(
chan
*
ipld
.
NodeOption
,
len
(
keys
))
out
:=
make
(
chan
*
ipld
.
NodeOption
,
len
(
keys
))
blocks
:=
bs
.
GetBlocks
(
ctx
,
keys
)
blocks
:=
bs
.
GetBlocks
(
ctx
,
keys
)
var
count
int
var
count
int
...
...
merkledag_test.go
View file @
d3cca0ac
...
@@ -550,6 +550,36 @@ func TestCidRawDoesnNeedData(t *testing.T) {
...
@@ -550,6 +550,36 @@ func TestCidRawDoesnNeedData(t *testing.T) {
}
}
}
}
func
TestGetManyDuplicate
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
srv
:=
NewDAGService
(
dstest
.
Bserv
())
nd
:=
NodeWithData
([]
byte
(
"foo"
))
if
err
:=
srv
.
Add
(
ctx
,
nd
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
nds
:=
srv
.
GetMany
(
ctx
,
[]
*
cid
.
Cid
{
nd
.
Cid
(),
nd
.
Cid
(),
nd
.
Cid
()})
out
,
ok
:=
<-
nds
if
!
ok
{
t
.
Fatal
(
"expecting node foo"
)
}
if
out
.
Err
!=
nil
{
t
.
Fatal
(
out
.
Err
)
}
if
!
out
.
Node
.
Cid
()
.
Equals
(
nd
.
Cid
())
{
t
.
Fatal
(
"got wrong node"
)
}
out
,
ok
=
<-
nds
if
ok
{
if
out
.
Err
!=
nil
{
t
.
Fatal
(
out
.
Err
)
}
else
{
t
.
Fatal
(
"expecting no more nodes"
)
}
}
}
func
TestEnumerateAsyncFailsNotFound
(
t
*
testing
.
T
)
{
func
TestEnumerateAsyncFailsNotFound
(
t
*
testing
.
T
)
{
ctx
:=
context
.
Background
()
ctx
:=
context
.
Background
()
...
...
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