From 333fcbaaebade41559c0652a3fb9a4005202104f Mon Sep 17 00:00:00 2001 From: vorotamoroz Date: Wed, 1 Mar 2023 12:58:29 +0900 Subject: [PATCH] - Fixed: - Requests of reading chunks online are now split into a reasonable(and configurable) size. - No longer error message will be shown on Linux devices with hidden file synchronisation. - Improved: - The interval of reading chunks online is now configurable. - Boot sequence has been speeded up, more. - Misc: - Messages on the boot sequence will now be more detailed. If you want to see them, please enable the verbose log. - Logs became be kept for 1000 lines while the verbose log is enabled. --- src/ObsidianLiveSyncSettingTab.ts | 36 ++++++++++++++++++++++++++++++- src/lib | 2 +- src/main.ts | 35 +++++++++--------------------- 3 files changed, 46 insertions(+), 27 deletions(-) diff --git a/src/ObsidianLiveSyncSettingTab.ts b/src/ObsidianLiveSyncSettingTab.ts index 20d1794..09ef3b5 100644 --- a/src/ObsidianLiveSyncSettingTab.ts +++ b/src/ObsidianLiveSyncSettingTab.ts @@ -453,6 +453,9 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab { this.plugin.settings.syncOnStart = false; this.plugin.settings.syncOnFileOpen = false; this.plugin.settings.syncAfterMerge = false; + this.plugin.settings.syncInternalFiles = false; + this.plugin.settings.usePluginSync = false; + Logger("Hidden files and plugin synchronization have been temporarily disabled. Please enable them after the fetching, if you need them.", LOG_LEVEL.NOTICE) await this.plugin.saveSettings(); applyDisplayEnabled(); @@ -1324,7 +1327,38 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab { }); text.inputEl.setAttribute("type", "number"); }); - + new Setting(containerSyncSettingEl) + .setName("The maximum number of reading chunks online concurrently") + .setDesc("") + .addText((text) => { + text.setPlaceholder("") + .setValue(this.plugin.settings.concurrencyOfReadChunksOnline + "") + .onChange(async (value) => { + let v = Number(value); + if (isNaN(v) || v < 10) { + v = 10; + } + this.plugin.settings.concurrencyOfReadChunksOnline = v; + await this.plugin.saveSettings(); + }); + text.inputEl.setAttribute("type", "number"); + }); + new Setting(containerSyncSettingEl) + .setName("The minimum interval for reading chunks online") + .setDesc("") + .addText((text) => { + text.setPlaceholder("") + .setValue(this.plugin.settings.minimumIntervalOfReadChunksOnline + "") + .onChange(async (value) => { + let v = Number(value); + if (isNaN(v) || v < 10) { + v = 10; + } + this.plugin.settings.minimumIntervalOfReadChunksOnline = v; + await this.plugin.saveSettings(); + }); + text.inputEl.setAttribute("type", "number"); + }); addScreenElement("30", containerSyncSettingEl); const containerMiscellaneousEl = containerEl.createDiv(); containerMiscellaneousEl.createEl("h3", { text: "Miscellaneous" }); diff --git a/src/lib b/src/lib index 45169f7..f5ca1c0 160000 --- a/src/lib +++ b/src/lib @@ -1 +1 @@ -Subproject commit 45169f72f47bd78ec728bf842ae589c95856d477 +Subproject commit f5ca1c09d9000dc1edff98a7e3c79bfdfe69d2fe diff --git a/src/main.ts b/src/main.ts index 83a00e2..a3f8ca4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1302,7 +1302,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin { } this.app.vault.adapter.append(normalizePath(logDate), vaultName + ":" + newMessage + "\n"); } - logMessageStore.apply(e => [...e, newMessage].slice(-100)); + logMessageStore.apply(e => [...e, newMessage].slice(this.settings.showVerboseLog ? -1000 : -100)); this.setStatusBarText(null, messageContent); if (level >= LOG_LEVEL.NOTICE) { @@ -1571,9 +1571,10 @@ export default class ObsidianLiveSyncPlugin extends Plugin { const filename = id2path(id2filenameInternalMetadata(queue.entry._id)); // await this.syncInternalFilesAndDatabase("pull", false, false, [filename]) this.procInternalFile(filename); - } - if (isValidPath(id2path(queue.entry._id))) { + } else if (isValidPath(id2path(queue.entry._id))) { this.handleDBChanged(queue.entry); + } else { + Logger(`Skipped: ${queue.entry._id}`, LOG_LEVEL.VERBOSE); } } else if (now > queue.timeout) { if (!queue.warned) Logger(`Timed out: ${queue.entry._id} could not collect ${queue.missingChildren.length} chunks. plugin keeps watching, but you have to check the file after the replication.`, LOG_LEVEL.NOTICE); @@ -1983,12 +1984,13 @@ export default class ObsidianLiveSyncPlugin extends Plugin { const filesStorageName = filesStorage.map((e) => e.path); Logger("Collecting local files on the DB", LOG_LEVEL.VERBOSE); const filesDatabase = [] as string[] - for await (const doc of this.localDatabase.findAllDocs()) { - const path = id2path(doc._id); - if (isValidPath(doc._id) && this.isTargetFile(path)) { + for await (const docId of this.localDatabase.findAllDocNames()) { + const path = id2path(docId); + if (isValidPath(docId) && this.isTargetFile(path)) { filesDatabase.push(path); } } + Logger("Opening the key-value database", LOG_LEVEL.VERBOSE); const isInitialized = await (this.localDatabase.kvDB.get("initialized")) || false; // Make chunk bigger if it is the initial scan. There must be non-active docs. @@ -2006,28 +2008,14 @@ export default class ObsidianLiveSyncPlugin extends Plugin { this.setStatusBarText(`UPDATE DATABASE`); const runAll = async(procedureName: string, objects: T[], callback: (arg: T) => Promise) => { - // const count = objects.length; Logger(procedureName); - // let i = 0; const semaphore = Semaphore(25); - - // Logger(`${procedureName} exec.`); if (!this.localDatabase.isReady) throw Error("Database is not ready!"); const processes = objects.map(e => (async (v) => { const releaser = await semaphore.acquire(1, procedureName); try { await callback(v); - // i++; - // if (i % 50 == 0) { - // const notify = `${procedureName} : ${i}/${count}`; - // if (showingNotice) { - // Logger(notify, LOG_LEVEL.NOTICE, "syncAll"); - // } else { - // Logger(notify); - // } - // this.setStatusBarText(notify); - // } } catch (ex) { Logger(`Error while ${procedureName}`, LOG_LEVEL.NOTICE); Logger(ex); @@ -2067,7 +2055,6 @@ export default class ObsidianLiveSyncPlugin extends Plugin { const syncFilesX = syncFiles.splice(0, 100); const docs = await this.localDatabase.localDatabase.allDocs({ keys: syncFilesX.map(e => path2id(e.path)), include_docs: true }) const syncFilesToSync = syncFilesX.map((e) => ({ file: e, doc: docs.rows.find(ee => ee.id == path2id(e.path)).doc as LoadedEntry })); - await runAll(`CHECK FILE STATUS:${syncFiles.length}/${docsCount}`, syncFilesToSync, async (e) => { caches = await this.syncFileBetweenDBandStorage(e.file, e.doc, initialScan, caches); }); @@ -2674,6 +2661,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin { const dK = `${file.path}-diff`; const isLastDiff = dK in caches ? caches[dK] : { storageMtime: 0, docMtime: 0 }; if (isLastDiff.docMtime == docMtime && isLastDiff.storageMtime == storageMtime) { + Logger("STORAGE .. DB :" + file.path, LOG_LEVEL.VERBOSE); caches[dK] = { storageMtime, docMtime }; return caches; } @@ -2696,11 +2684,8 @@ export default class ObsidianLiveSyncPlugin extends Plugin { } caches[dK] = { storageMtime, docMtime }; return caches; - } else { - // Logger("EVEN :" + file.path, LOG_LEVEL.VERBOSE); - // Logger(`${storageMtime} = ${docMtime}`, LOG_LEVEL.VERBOSE); - //eq.case } + Logger("STORAGE == DB :" + file.path + "", LOG_LEVEL.VERBOSE); caches[dK] = { storageMtime, docMtime }; return caches;