@@ -52,16 +52,40 @@ export class DataviewSerializerPlugin extends Plugin {
5252 true
5353 ) ;
5454
55- scheduleFullUpdate = debounce (
56- this . processAllFiles . bind ( this ) ,
55+ scheduleForcedUpdate = debounce (
56+ this . processForceUpdateFiles . bind ( this ) ,
5757 MINIMUM_MS_BETWEEN_EVENTS * 20 ,
5858 true
5959 ) ;
6060
61- async processAllFiles ( ) : Promise < void > {
62- this . app . vault . getMarkdownFiles ( ) . forEach ( ( file ) => {
63- this . processFile ( file ) ;
64- } ) ;
61+ /**
62+ * Process updates for folders which are marked as forced updates.
63+ * These files are updated on any modification, useful for scenarios
64+ * where there's an index file that holds queries that could be impacted
65+ * by file updates elsewhere. This can be run with an empty argument list,
66+ * or with `true` passed as a value to the single optional parameter to
67+ * update all files. The command palette command uses this behavior.
68+ */
69+ async processForceUpdateFiles ( allFiles ?: boolean ) : Promise < void > {
70+ this . app . vault
71+ . getMarkdownFiles ( )
72+ . filter ( ( file ) => {
73+ if ( allFiles ) {
74+ // Ignore the configuration and update all queries when this parameter is true
75+ return true ;
76+ }
77+ let isUpdateable = false ;
78+ this . settings . foldersToForceUpdate . forEach ( ( folder ) => {
79+ if ( file . path . startsWith ( folder ) ) {
80+ isUpdateable = true ;
81+ }
82+ } ) ;
83+
84+ return isUpdateable ;
85+ } )
86+ . forEach ( async ( file ) => {
87+ await this . processFile ( file ) ;
88+ } ) ;
6589 }
6690 /**
6791 * Process all the identified recently updated files
@@ -105,11 +129,7 @@ export class DataviewSerializerPlugin extends Plugin {
105129 name : 'Scan and serialize all Dataview queries' ,
106130 callback : async ( ) => {
107131 log ( 'Scanning and serializing all Dataview queries' , 'debug' ) ;
108- const allVaultFiles = this . app . vault . getMarkdownFiles ( ) ;
109-
110- for ( const vaultFile of allVaultFiles ) {
111- await this . processFile ( vaultFile ) ;
112- }
132+ this . processForceUpdateFiles ( true ) ;
113133 } ,
114134 } ) ;
115135 }
@@ -153,6 +173,19 @@ export class DataviewSerializerPlugin extends Plugin {
153173 log ( 'The loaded settings miss the [ignoredFolders] property' , 'debug' ) ;
154174 needToSaveSettings = true ;
155175 }
176+ if (
177+ loadedSettings . foldersToForceUpdate !== undefined &&
178+ loadedSettings . foldersToForceUpdate !== null &&
179+ Array . isArray ( loadedSettings . foldersToForceUpdate )
180+ ) {
181+ draft . foldersToForceUpdate = loadedSettings . foldersToForceUpdate ;
182+ } else {
183+ log (
184+ 'The loaded settings miss the [foldersToForceUpdate] property' ,
185+ 'debug'
186+ ) ;
187+ needToSaveSettings = true ;
188+ }
156189 } ) ;
157190
158191 log ( `Settings loaded` , 'debug' , loadedSettings ) ;
@@ -183,23 +216,23 @@ export class DataviewSerializerPlugin extends Plugin {
183216 this . app . vault . on ( 'create' , ( file ) => {
184217 this . recentlyUpdatedFiles . add ( file ) ;
185218 this . scheduleUpdate ( ) ;
186- this . scheduleFullUpdate ( ) ;
219+ this . scheduleForcedUpdate ( ) ;
187220 } )
188221 ) ;
189222
190223 this . registerEvent (
191224 this . app . vault . on ( 'rename' , ( file ) => {
192225 this . recentlyUpdatedFiles . add ( file ) ;
193226 this . scheduleUpdate ( ) ;
194- this . scheduleFullUpdate ( ) ;
227+ this . scheduleForcedUpdate ( ) ;
195228 } )
196229 ) ;
197230
198231 this . registerEvent (
199232 this . app . vault . on ( 'modify' , ( file ) => {
200233 this . recentlyUpdatedFiles . add ( file ) ;
201234 this . scheduleUpdate ( ) ;
202- this . scheduleFullUpdate ( ) ;
235+ this . scheduleForcedUpdate ( ) ;
203236 } )
204237 ) ;
205238 } ) ;
@@ -221,6 +254,7 @@ export class DataviewSerializerPlugin extends Plugin {
221254 try {
222255 //log(`Processing file: ${file.path}`, 'debug');
223256
257+ // check cached text for queries
224258 const cachedText = await this . app . vault . cachedRead ( file ) ;
225259 const foundQueries : string [ ] = findQueries ( cachedText ) ;
226260
@@ -229,6 +263,7 @@ export class DataviewSerializerPlugin extends Plugin {
229263 return ;
230264 }
231265
266+ // get text from filesystem, per documentation, since we'll likely be changing it
232267 const text = await this . app . vault . read ( file ) ;
233268
234269 // Process the modified file
@@ -286,6 +321,7 @@ export class DataviewSerializerPlugin extends Plugin {
286321
287322 if ( updatedText !== text ) {
288323 //log('The file content has changed. Saving the modifications', 'info');
324+
289325 await this . app . vault . modify ( file , updatedText ) ;
290326 }
291327 } catch ( e : unknown ) {
0 commit comments