@@ -20,8 +20,12 @@ class ComplexIPLDGraph {
20
20
}
21
21
this . cbor = cbor ( ( ...args ) => store . get ( ...args ) )
22
22
this . store = store
23
+ this . _clear ( )
24
+ }
25
+ _clear ( ) {
23
26
this . _pending = new Map ( )
24
27
this . _patches = new Map ( )
28
+ this . _bulk = null
25
29
}
26
30
shardPath ( path , handler ) {
27
31
path = path . split ( '/' ) . filter ( x => x )
@@ -69,6 +73,7 @@ class ComplexIPLDGraph {
69
73
path = await this . _realKey ( path )
70
74
this . _bulk . put ( block . cid , block . data )
71
75
nest ( this . _patches , path , block . cid )
76
+ this . _draining = null
72
77
}
73
78
} ) ( )
74
79
}
@@ -86,6 +91,7 @@ class ComplexIPLDGraph {
86
91
root = this . root
87
92
}
88
93
if ( ! root ) throw new Error ( 'No root node.' )
94
+ root = mkcid ( root )
89
95
await this . _kick ( )
90
96
await this . _kick ( )
91
97
@@ -104,17 +110,18 @@ class ComplexIPLDGraph {
104
110
let _iter = async ( map , node ) => {
105
111
for ( let [ key , value ] of map . entries ( ) ) {
106
112
if ( value instanceof Map ) {
113
+ let _node
114
+ let cid
107
115
if ( node [ key ] ) {
108
- let cid = mkcid ( node [ key ] [ '/' ] )
109
- let _node = this . get ( cid )
110
- let _cid = await _iter ( value , _node )
111
- node [ key ] = toLink ( _cid )
112
- if ( clobber &&
113
- _cid . toBaseEncodedString ( ) !== cid . toBaseEncodedString ( ) ) {
114
- this . _bulk . del ( cid )
115
- }
116
+ cid = mkcid ( node [ key ] [ '/' ] )
117
+ _node = await this . get ( cid )
116
118
} else {
117
- node [ key ] = toLink ( await _iter ( value , { } ) )
119
+ _node = { }
120
+ }
121
+ node [ key ] = toLink ( await _iter ( value , _node ) )
122
+ if ( clobber && cid &&
123
+ node [ key ] [ '/' ] !== cid . toBaseEncodedString ( ) ) {
124
+ this . _bulk . del ( cid )
118
125
}
119
126
} else {
120
127
if ( ! ( value instanceof CID ) ) throw new Error ( 'Value not CID.' )
@@ -123,14 +130,22 @@ class ComplexIPLDGraph {
123
130
}
124
131
return mkcbor ( node )
125
132
}
133
+
126
134
let start = Date . now ( )
127
135
let cid = await _iter ( this . _patches , await this . get ( root ) )
128
136
this . _graphBuildTime = Date . now ( ) - start
129
137
138
+ if ( clobber &&
139
+ root . toBaseEncodedString ( ) !== cid . toBaseEncodedString ( ) ) {
140
+ this . _bulk . del ( root )
141
+ }
142
+
130
143
start = Date . now ( )
131
144
await this . _bulk . flush ( )
132
145
this . _flushTime = Date . now ( ) - start
133
146
147
+ this . _clear ( )
148
+
134
149
return cid
135
150
}
136
151
0 commit comments