- Fixed the Infinity loop
This commit is contained in:
vorotamoroz
2022-10-21 18:20:03 +09:00
parent c18b5c24b4
commit d9b69d9a1b
+38 -33
View File
@@ -841,42 +841,45 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
} }
} }
clearTrigger("applyBatchAuto"); clearTrigger("applyBatchAuto");
const ret = await runWithLock("procFiles", false, async () => { const ret = await runWithLock("procFiles", true, async () => {
const procs = [...this.watchedFileEventQueue]; do {
this.watchedFileEventQueue = []; const procs = [...this.watchedFileEventQueue];
for (const queue of procs) { this.watchedFileEventQueue = [];
const file = queue.args.file; for (const queue of procs) {
const key = `file-last-proc-${queue.type}-${file.path}`; const file = queue.args.file;
const last = Number(await this.localDatabase.kvDB.get(key) || 0); const key = `file-last-proc-${queue.type}-${file.path}`;
if (file instanceof TFile && file.stat.mtime == last) { const last = Number(await this.localDatabase.kvDB.get(key) || 0);
Logger(`File has been already scanned on ${queue.type}, skip: ${file.path}`, LOG_LEVEL.VERBOSE); if (file instanceof TFile && file.stat.mtime == last) {
continue; Logger(`File has been already scanned on ${queue.type}, skip: ${file.path}`, LOG_LEVEL.VERBOSE);
} continue;
}
const cache = queue.args.cache; const cache = queue.args.cache;
if ((queue.type == "CREATE" || queue.type == "CHANGED") && file instanceof TFile) { if ((queue.type == "CREATE" || queue.type == "CHANGED") && file instanceof TFile) {
await this.updateIntoDB(file, false, cache); await this.updateIntoDB(file, false, cache);
} }
if (queue.type == "DELETE") { if (queue.type == "DELETE") {
if (file instanceof TFile) {
await this.deleteFromDB(file);
} else if (file instanceof TFolder) {
await this.deleteFolderOnDB(file);
}
}
if (queue.type == "RENAME") {
if (file instanceof TFile) {
await this.watchVaultRenameAsync(file, queue.args.oldPath);
}
}
if (queue.type == "INTERNAL") {
await this.watchVaultRawEventsAsync(file.path);
}
if (file instanceof TFile) { if (file instanceof TFile) {
await this.deleteFromDB(file); await this.localDatabase.kvDB.set(key, file.stat.mtime);
} else if (file instanceof TFolder) {
await this.deleteFolderOnDB(file);
} }
} }
if (queue.type == "RENAME") { this.refreshStatusText();
if (file instanceof TFile) { } while (this.watchedFileEventQueue.length != 0);
await this.watchVaultRenameAsync(file, queue.args.oldPath); return true;
}
}
if (queue.type == "INTERNAL") {
await this.watchVaultRawEventsAsync(file.path);
}
if (file instanceof TFile) {
await this.localDatabase.kvDB.set(key, file.stat.mtime);
}
}
this.refreshStatusText();
}) })
this.refreshStatusText(); this.refreshStatusText();
return ret; return ret;
@@ -917,7 +920,9 @@ export default class ObsidianLiveSyncPlugin extends Plugin {
} }
async applyBatchChange() { async applyBatchChange() {
return await this.procFileEvent(true); if (this.settings.batchSave) {
return await this.procFileEvent(true);
}
} }
// Watch raw events (Internal API) // Watch raw events (Internal API)