@@ -61,16 +61,16 @@ export class TimeTreeCalculator {
6161
6262 async calculateRecursiveElapsedChild (
6363 file : TFile ,
64- recursive : boolean = true ,
65- includeOwn : boolean = true
64+ recursive : boolean = true
6665 ) : Promise < number > {
67- const content = await this . app . vault . read ( file ) ;
68- const yamlRegex = / ^ - - - \n ( [ \s \S ] * ?) \n - - - / ;
69- const yamlMatch = content . match ( yamlRegex ) ;
70- let frontmatter = yamlMatch ? YAML . parse ( yamlMatch [ 1 ] ) || { } : { } ;
71- const ownElapsed = frontmatter . elapsed || 0 ;
66+ const ownElapsed = await this . frontMatterManager . getProperty (
67+ file ,
68+ "elapsed"
69+ ) ;
7270 const fileCache = this . app . metadataCache . getFileCache ( file ) ;
73- if ( ! fileCache || ! fileCache . links || fileCache . links . length === 0 ) {
71+ const childNotes = ( fileCache as any ) . links ;
72+ const leafNote = ! fileCache || ! childNotes || childNotes . length === 0 ;
73+ if ( leafNote ) {
7474 const properties =
7575 ownElapsed === 0
7676 ? [ "elapsed" , "elapsed_child" ]
@@ -84,7 +84,7 @@ export class TimeTreeCalculator {
8484 return ownElapsed ;
8585 }
8686 let totalDescendantElapsed = 0 ;
87- for ( const link of fileCache . links ) {
87+ for ( const link of childNotes ) {
8888 const childFile = this . app . metadataCache . getFirstLinkpathDest (
8989 link . link ,
9090 file . path
@@ -97,15 +97,15 @@ export class TimeTreeCalculator {
9797 ) ;
9898 } else {
9999 const childElapsed =
100- ( await this . frontMatterManager . getProperty (
100+ await this . frontMatterManager . getProperty (
101101 childFile ,
102102 "elapsed"
103- ) ) || 0 ;
103+ ) ;
104104 const childElapsedChilds =
105- ( await this . frontMatterManager . getProperty (
105+ await this . frontMatterManager . getProperty (
106106 childFile ,
107107 "elapsed_child"
108- ) ) || 0 ;
108+ ) ;
109109 childTotal = childElapsed + childElapsedChilds ;
110110 }
111111 totalDescendantElapsed += childTotal ;
@@ -115,21 +115,13 @@ export class TimeTreeCalculator {
115115 fm . elapsed_child = totalDescendantElapsed ;
116116 return fm ;
117117 } ) ;
118- const total = includeOwn
119- ? ownElapsed + totalDescendantElapsed
120- : totalDescendantElapsed ;
121- return total ;
118+ return ownElapsed + totalDescendantElapsed ;
122119 }
123120
124121 async communicateAscendants ( file : TFile ) : Promise < void > {
125122 const parent = await this . getParentFile ( file ) ;
126123 if ( parent ) {
127- const parentElapsedChild =
128- await this . calculateRecursiveElapsedChild ( parent , false , false ) ;
129- await this . frontMatterManager . updateProperty ( parent , ( fm ) => {
130- fm . elapsed_child = parentElapsedChild ;
131- return fm ;
132- } ) ;
124+ await this . calculateRecursiveElapsedChild ( parent , false ) ;
133125 await this . communicateAscendants ( parent ) ;
134126 }
135127 return ;
@@ -226,14 +218,14 @@ export class TimeTreeCalculator {
226218 const files = [ file , ...descendantFiles ] ;
227219 const accValues : { file : TFile ; acc : number } [ ] = [ ] ;
228220 for ( const file of files ) {
229- const elapsed =
230- ( await this . frontMatterManager . getProperty ( file , "elapsed" ) ) ||
231- 0 ;
232- const elapsedChild =
233- ( await this . frontMatterManager . getProperty (
234- file ,
235- "elapsed_child"
236- ) ) || 0 ;
221+ const elapsed = await this . frontMatterManager . getProperty (
222+ file ,
223+ "elapsed"
224+ ) ;
225+ const elapsedChild = await this . frontMatterManager . getProperty (
226+ file ,
227+ "elapsed_child"
228+ ) ;
237229 const acc = elapsed + elapsedChild ;
238230 accValues . push ( { file, acc } ) ;
239231 }
@@ -257,7 +249,8 @@ export class TimeTreeCalculator {
257249 await this . frontMatterManager . updateProperty (
258250 file ,
259251 ( frontmatter ) => {
260- frontmatter . node_size = node_size ;
252+ frontmatter . node_size =
253+ typeof node_size === "number" ? node_size : min_d ;
261254 return frontmatter ;
262255 }
263256 ) ;
0 commit comments