@@ -61,16 +61,16 @@ export class TimeTreeCalculator {
61
61
62
62
async calculateRecursiveElapsedChild (
63
63
file : TFile ,
64
- recursive : boolean = true ,
65
- includeOwn : boolean = true
64
+ recursive : boolean = true
66
65
) : 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
+ ) ;
72
70
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 ) {
74
74
const properties =
75
75
ownElapsed === 0
76
76
? [ "elapsed" , "elapsed_child" ]
@@ -84,7 +84,7 @@ export class TimeTreeCalculator {
84
84
return ownElapsed ;
85
85
}
86
86
let totalDescendantElapsed = 0 ;
87
- for ( const link of fileCache . links ) {
87
+ for ( const link of childNotes ) {
88
88
const childFile = this . app . metadataCache . getFirstLinkpathDest (
89
89
link . link ,
90
90
file . path
@@ -97,15 +97,15 @@ export class TimeTreeCalculator {
97
97
) ;
98
98
} else {
99
99
const childElapsed =
100
- ( await this . frontMatterManager . getProperty (
100
+ await this . frontMatterManager . getProperty (
101
101
childFile ,
102
102
"elapsed"
103
- ) ) || 0 ;
103
+ ) ;
104
104
const childElapsedChilds =
105
- ( await this . frontMatterManager . getProperty (
105
+ await this . frontMatterManager . getProperty (
106
106
childFile ,
107
107
"elapsed_child"
108
- ) ) || 0 ;
108
+ ) ;
109
109
childTotal = childElapsed + childElapsedChilds ;
110
110
}
111
111
totalDescendantElapsed += childTotal ;
@@ -115,21 +115,13 @@ export class TimeTreeCalculator {
115
115
fm . elapsed_child = totalDescendantElapsed ;
116
116
return fm ;
117
117
} ) ;
118
- const total = includeOwn
119
- ? ownElapsed + totalDescendantElapsed
120
- : totalDescendantElapsed ;
121
- return total ;
118
+ return ownElapsed + totalDescendantElapsed ;
122
119
}
123
120
124
121
async communicateAscendants ( file : TFile ) : Promise < void > {
125
122
const parent = await this . getParentFile ( file ) ;
126
123
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 ) ;
133
125
await this . communicateAscendants ( parent ) ;
134
126
}
135
127
return ;
@@ -226,14 +218,14 @@ export class TimeTreeCalculator {
226
218
const files = [ file , ...descendantFiles ] ;
227
219
const accValues : { file : TFile ; acc : number } [ ] = [ ] ;
228
220
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
+ ) ;
237
229
const acc = elapsed + elapsedChild ;
238
230
accValues . push ( { file, acc } ) ;
239
231
}
@@ -257,7 +249,8 @@ export class TimeTreeCalculator {
257
249
await this . frontMatterManager . updateProperty (
258
250
file ,
259
251
( frontmatter ) => {
260
- frontmatter . node_size = node_size ;
252
+ frontmatter . node_size =
253
+ typeof node_size === "number" ? node_size : min_d ;
261
254
return frontmatter ;
262
255
}
263
256
) ;
0 commit comments