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
f8108394
Commit
f8108394
authored
Feb 20, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rework FetchGraph to be less of a memory hog
License: MIT Signed-off-by:
Jeromy
<
jeromyj@gmail.com
>
parent
172550b4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
17 deletions
+22
-17
merkledag.go
merkledag.go
+22
-17
No files found.
merkledag.go
View file @
f8108394
...
...
@@ -149,6 +149,8 @@ func (ds *dagService) GetMany(ctx context.Context, keys []key.Key) (<-chan *Node
out
:=
make
(
chan
*
Node
)
errs
:=
make
(
chan
error
,
1
)
blocks
:=
ds
.
Blocks
.
GetBlocks
(
ctx
,
keys
)
var
count
int
go
func
()
{
defer
close
(
out
)
defer
close
(
errs
)
...
...
@@ -156,6 +158,9 @@ func (ds *dagService) GetMany(ctx context.Context, keys []key.Key) (<-chan *Node
select
{
case
b
,
ok
:=
<-
blocks
:
if
!
ok
{
if
count
!=
len
(
keys
)
{
errs
<-
fmt
.
Errorf
(
"failed to fetch all nodes"
)
}
return
}
nd
,
err
:=
Decoded
(
b
.
Data
)
...
...
@@ -165,6 +170,7 @@ func (ds *dagService) GetMany(ctx context.Context, keys []key.Key) (<-chan *Node
}
select
{
case
out
<-
nd
:
count
++
case
<-
ctx
.
Done
()
:
return
}
...
...
@@ -404,28 +410,27 @@ func EnumerateChildrenAsync(ctx context.Context, ds DAGService, root *Node, set
func
fetchNodes
(
ctx
context
.
Context
,
ds
DAGService
,
in
<-
chan
[]
key
.
Key
,
out
chan
<-
*
Node
,
errs
chan
<-
error
)
{
defer
close
(
out
)
get
:=
func
(
g
NodeGetter
)
{
n
d
,
err
:=
g
.
Get
(
ctx
)
if
err
!=
nil
{
get
:=
func
(
ks
[]
key
.
Key
)
{
n
odes
,
err
ch
:=
ds
.
Get
Many
(
ctx
,
ks
)
for
{
select
{
case
errs
<-
err
:
case
<-
ctx
.
Done
()
:
case
nd
,
ok
:=
<-
nodes
:
if
!
ok
{
return
}
select
{
case
out
<-
nd
:
case
<-
ctx
.
Done
()
:
return
}
case
err
:=
<-
errch
:
errs
<-
err
return
}
return
}
select
{
case
out
<-
nd
:
case
<-
ctx
.
Done
()
:
return
}
}
for
ks
:=
range
in
{
ng
:=
GetNodes
(
ctx
,
ds
,
ks
)
for
_
,
g
:=
range
ng
{
go
get
(
g
)
}
go
get
(
ks
)
}
}
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