@@ -15,9 +15,12 @@ async function pinsToDatastore (blockstore, datastore, pinstore, onProgress) {
15
15
const cid = new CID ( mh )
16
16
const pinRootBuf = await blockstore . get ( cidToKey ( cid ) )
17
17
const pinRoot = dagpb . util . deserialize ( pinRootBuf )
18
-
19
- const pinCount = ( await length ( pinset . loadSet ( blockstore , pinRoot , PinTypes . recursive ) ) ) + ( await length ( pinset . loadSet ( blockstore , pinRoot , PinTypes . direct ) ) )
20
18
let counter = 0
19
+ let pinCount
20
+
21
+ if ( onProgress ) {
22
+ pinCount = ( await length ( pinset . loadSet ( blockstore , pinRoot , PinTypes . recursive ) ) ) + ( await length ( pinset . loadSet ( blockstore , pinRoot , PinTypes . direct ) ) )
23
+ }
21
24
22
25
for await ( const cid of pinset . loadSet ( blockstore , pinRoot , PinTypes . recursive ) ) {
23
26
counter ++
@@ -35,7 +38,9 @@ async function pinsToDatastore (blockstore, datastore, pinstore, onProgress) {
35
38
36
39
await pinstore . put ( cidToKey ( cid ) , cbor . encode ( pin ) )
37
40
38
- onProgress ( ( counter / pinCount ) * 100 , `Migrated recursive pin ${ cid } ` )
41
+ if ( onProgress ) {
42
+ onProgress ( ( counter / pinCount ) * 100 , `Migrated recursive pin ${ cid } ` )
43
+ }
39
44
}
40
45
41
46
for await ( const cid of pinset . loadSet ( blockstore , pinRoot , PinTypes . direct ) ) {
@@ -64,15 +69,13 @@ async function pinsToDatastore (blockstore, datastore, pinstore, onProgress) {
64
69
async function pinsToDAG ( blockstore , datastore , pinstore , onProgress ) {
65
70
let recursivePins = [ ]
66
71
let directPins = [ ]
67
-
72
+ let counter = 0
68
73
let pinCount
69
74
70
75
if ( onProgress ) {
71
76
pinCount = await length ( pinstore . query ( { keysOnly : true } ) )
72
77
}
73
78
74
- let counter = 0
75
-
76
79
for await ( const { key, value } of pinstore . query ( { } ) ) {
77
80
counter ++
78
81
const pin = cbor . decode ( value )
0 commit comments