@@ -15,9 +15,12 @@ async function pinsToDatastore (blockstore, datastore, pinstore, onProgress) {
1515 const cid = new CID ( mh )
1616 const pinRootBuf = await blockstore . get ( cidToKey ( cid ) )
1717 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 ) ) )
2018 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+ }
2124
2225 for await ( const cid of pinset . loadSet ( blockstore , pinRoot , PinTypes . recursive ) ) {
2326 counter ++
@@ -35,7 +38,9 @@ async function pinsToDatastore (blockstore, datastore, pinstore, onProgress) {
3538
3639 await pinstore . put ( cidToKey ( cid ) , cbor . encode ( pin ) )
3740
38- onProgress ( ( counter / pinCount ) * 100 , `Migrated recursive pin ${ cid } ` )
41+ if ( onProgress ) {
42+ onProgress ( ( counter / pinCount ) * 100 , `Migrated recursive pin ${ cid } ` )
43+ }
3944 }
4045
4146 for await ( const cid of pinset . loadSet ( blockstore , pinRoot , PinTypes . direct ) ) {
@@ -64,15 +69,13 @@ async function pinsToDatastore (blockstore, datastore, pinstore, onProgress) {
6469async function pinsToDAG ( blockstore , datastore , pinstore , onProgress ) {
6570 let recursivePins = [ ]
6671 let directPins = [ ]
67-
72+ let counter = 0
6873 let pinCount
6974
7075 if ( onProgress ) {
7176 pinCount = await length ( pinstore . query ( { keysOnly : true } ) )
7277 }
7378
74- let counter = 0
75-
7679 for await ( const { key, value } of pinstore . query ( { } ) ) {
7780 counter ++
7881 const pin = cbor . decode ( value )
0 commit comments