@@ -50,6 +50,16 @@ const fileFromStats = ({ cumulativeSize, type, size, cid, name, path, pinned, is
50
50
isParent : isParent
51
51
} )
52
52
53
+ /**
54
+ * @param {IPFSService } ipfs
55
+ * @param {string|CID } cidOrPath
56
+ * @returns {number }
57
+ */
58
+ const cumulativeSize = async ( ipfs , cidOrPath ) => {
59
+ const { cumulativeSize } = await stat ( ipfs , cidOrPath )
60
+ return cumulativeSize || 0
61
+ }
62
+
53
63
/**
54
64
* @param {string } path
55
65
* @returns {string }
@@ -81,6 +91,7 @@ const stat = async (ipfs, cidOrPath) => {
81
91
: `/ipfs/${ hashOrPath } `
82
92
83
93
try {
94
+ // TODO: memoize/cache result per CID
84
95
const stats = await ipfs . files . stat ( path )
85
96
return { path, ...stats }
86
97
} catch ( e ) {
@@ -512,13 +523,10 @@ const actions = () => ({
512
523
* updated.
513
524
*/
514
525
doPinsSizeGet : ( ) => perform ( ACTIONS . PINS_SIZE_GET , async ( ipfs ) => {
515
- const allPinsCids = await ipfs . pin . ls ( { type : 'recursive' } )
516
-
517
- let pinsSize = 0
526
+ const pinsSize = - 1 // TODO: right now calculating size of all pins is too expensive (requires ipfs.files.stat per CID)
518
527
let numberOfPins = 0
519
528
520
- for await ( const { cid } of allPinsCids ) {
521
- pinsSize += ( await ipfs . files . stat ( `/ipfs/${ cid . toString ( ) } ` ) ) . cumulativeSize
529
+ for await ( const _ of ipfs . pin . ls ( { type : 'recursive' } ) ) { // eslint-disable-line no-unused-vars
522
530
numberOfPins ++
523
531
}
524
532
@@ -530,8 +538,7 @@ const actions = () => ({
530
538
* updated.
531
539
*/
532
540
doFilesSizeGet : ( ) => perform ( ACTIONS . SIZE_GET , async ( ipfs ) => {
533
- const stat = await ipfs . files . stat ( '/' )
534
- return { size : stat . cumulativeSize }
541
+ return cumulativeSize ( ipfs , '/' )
535
542
} ) ,
536
543
537
544
/**
@@ -544,8 +551,7 @@ const actions = () => ({
544
551
*/
545
552
async ( store ) => {
546
553
const ipfs = store . getIpfs ( )
547
- const stat = await ipfs . files . stat ( `/ipfs/${ cid } ` )
548
- return stat . cumulativeSize
554
+ return cumulativeSize ( ipfs , cid )
549
555
}
550
556
} )
551
557
@@ -615,7 +621,7 @@ const dirStats = async (ipfs, cid, { path, isRoot, sorting }) => {
615
621
}
616
622
617
623
parent = fileFromStats ( {
618
- ...await ipfs . files . stat ( parentInfo . realPath ) ,
624
+ ...await stat ( ipfs , parentInfo . realPath ) ,
619
625
path : parentInfo . path ,
620
626
name : '..' ,
621
627
isParent : true
0 commit comments