Skip to content

Commit

Permalink
Revert "feat: Enable updates to all files, not just recently modified"
Browse files Browse the repository at this point in the history
This reverts commit 35cbd62.
  • Loading branch information
dsebastien authored Nov 26, 2024
1 parent dbf8f79 commit 0dafb5c
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions apps/plugin/src/app/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,6 @@ export class DataviewSerializerPlugin extends Plugin {
true
);

scheduleFullUpdate = debounce(
this.processAllFiles.bind(this),
MINIMUM_MS_BETWEEN_EVENTS * 20,
true
);

async processAllFiles(): Promise<void> {
this.app.vault.getMarkdownFiles().forEach((file) => {
this.processFile(file);
});
}
/**
* Process all the identified recently updated files
*/
Expand Down Expand Up @@ -183,23 +172,20 @@ export class DataviewSerializerPlugin extends Plugin {
this.app.vault.on('create', (file) => {
this.recentlyUpdatedFiles.add(file);
this.scheduleUpdate();
this.scheduleFullUpdate();
})
);

this.registerEvent(
this.app.vault.on('rename', (file) => {
this.recentlyUpdatedFiles.add(file);
this.scheduleUpdate();
this.scheduleFullUpdate();
})
);

this.registerEvent(
this.app.vault.on('modify', (file) => {
this.recentlyUpdatedFiles.add(file);
this.scheduleUpdate();
this.scheduleFullUpdate();
})
);
});
Expand All @@ -221,16 +207,14 @@ export class DataviewSerializerPlugin extends Plugin {
try {
//log(`Processing file: ${file.path}`, 'debug');

const cachedText = await this.app.vault.cachedRead(file);
const foundQueries: string[] = findQueries(cachedText);
const text = await this.app.vault.cachedRead(file);
const foundQueries: string[] = findQueries(text);

if (foundQueries.length === 0) {
// No queries to serialize found in the file
return;
}

const text = await this.app.vault.read(file);

// Process the modified file
let updatedText = `${text}`; // To ensure we have access to replaceAll...

Expand Down Expand Up @@ -277,7 +261,7 @@ export class DataviewSerializerPlugin extends Plugin {
}

// Keep track of the last time this file was updated to avoid modification loops
const nextPossibleUpdateTimeForFile = add(new Date(), {
const nextPossibleUpdateTimeForFile = add(new Date(file.stat.mtime), {
seconds: MINIMUM_SECONDS_BETWEEN_UPDATES,
});
this.nextPossibleUpdates.set(file.path, nextPossibleUpdateTimeForFile);
Expand Down Expand Up @@ -324,7 +308,7 @@ export class DataviewSerializerPlugin extends Plugin {
file.path
)!;

if (isBefore(new Date(), nextPossibleUpdateForFile)) {
if (isBefore(file.stat.mtime, nextPossibleUpdateForFile)) {
log('File has been updated recently. Ignoring', 'debug', file.path);
return true;
} else {
Expand Down

0 comments on commit 0dafb5c

Please sign in to comment.