From 842da980d789c8d61074180d6010386b8d644efe Mon Sep 17 00:00:00 2001 From: vorotamoroz Date: Wed, 17 May 2023 16:20:07 +0900 Subject: [PATCH] Improved: - Reduced remote database checking to improve speed and reduce bandwidth. Fixed: - Chunks which previously misinterpreted are now interpreted correctly. - Deleted file detection on hidden file synchronising now works fine. - Now the Customisation sync is surely quiet while it has been disabled. --- src/CmdConfigSync.ts | 3 ++- src/CmdHiddenFileSync.ts | 4 ++-- src/ObsidianLiveSyncSettingTab.ts | 4 ++-- src/lib | 2 +- src/main.ts | 18 +++++++++++------- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/CmdConfigSync.ts b/src/CmdConfigSync.ts index e8db71d..657901c 100644 --- a/src/CmdConfigSync.ts +++ b/src/CmdConfigSync.ts @@ -145,7 +145,7 @@ export class ConfigSync extends LiveSyncCommands { if (this.plugin.suspended) { return; } - if (this.settings.autoSweepPlugins) { + if (this.settings.autoSweepPlugins && this.settings.usePluginSync) { await this.scanAllConfigFiles(false); } this.periodicPluginSweepProcessor.enable(this.settings.autoSweepPluginsPeriodic && !this.settings.watchInternalFileChanges ? (PERIODIC_PLUGIN_SWEEP * 1000) : 0); @@ -567,6 +567,7 @@ export class ConfigSync extends LiveSyncCommands { } async watchVaultRawEventsAsync(path: FilePath) { + if (!this.settings.usePluginSync) return false; if (!this.isTargetPath(path)) return false; const stat = await this.app.vault.adapter.stat(path); // Make sure that target is a file. diff --git a/src/CmdHiddenFileSync.ts b/src/CmdHiddenFileSync.ts index 7819f40..30a8860 100644 --- a/src/CmdHiddenFileSync.ts +++ b/src/CmdHiddenFileSync.ts @@ -495,7 +495,7 @@ export class HiddenFileSync extends LiveSyncCommands { const mtime = new Date().getTime(); await runWithLock("file-" + prefixedFileName, false, async () => { try { - const old = await this.localDatabase.getDBEntry(prefixedFileName, null, false, false) as InternalFileEntry | false; + const old = await this.localDatabase.getDBEntryMeta(prefixedFileName, null, true) as InternalFileEntry | false; let saveData: InternalFileEntry; if (old === false) { saveData = { @@ -541,7 +541,7 @@ export class HiddenFileSync extends LiveSyncCommands { try { // Check conflicted status //TODO option - const fileOnDB = await this.localDatabase.getDBEntry(prefixedFileName, { conflicts: true }, false, false); + const fileOnDB = await this.localDatabase.getDBEntry(prefixedFileName, { conflicts: true }, false, true); if (fileOnDB === false) throw new Error(`File not found on database.:${filename}`); // Prevent overwrite for Prevent overwriting while some conflicted revision exists. diff --git a/src/ObsidianLiveSyncSettingTab.ts b/src/ObsidianLiveSyncSettingTab.ts index c88ee55..6f1dfaf 100644 --- a/src/ObsidianLiveSyncSettingTab.ts +++ b/src/ObsidianLiveSyncSettingTab.ts @@ -19,7 +19,7 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab { this.plugin = plugin; } async testConnection(): Promise { - const db = await this.plugin.replicator.connectRemoteCouchDBWithSetting(this.plugin.settings, this.plugin.isMobile); + const db = await this.plugin.replicator.connectRemoteCouchDBWithSetting(this.plugin.settings, this.plugin.isMobile, true); if (typeof db === "string") { this.plugin.addLog(`could not connect to ${this.plugin.settings.couchDB_URI} : ${this.plugin.settings.couchDB_DBNAME} \n(${db})`, LOG_LEVEL.NOTICE); return; @@ -376,7 +376,7 @@ export class ObsidianLiveSyncSettingTab extends PluginSettingTab { useDynamicIterationCount: useDynamicIterationCount, }; console.dir(settingForCheck); - const db = await this.plugin.replicator.connectRemoteCouchDBWithSetting(settingForCheck, this.plugin.isMobile); + const db = await this.plugin.replicator.connectRemoteCouchDBWithSetting(settingForCheck, this.plugin.isMobile, true); if (typeof db === "string") { Logger("Could not connect to the database.", LOG_LEVEL.NOTICE); return false; diff --git a/src/lib b/src/lib index 051b50c..ec4ecac 160000 --- a/src/lib +++ b/src/lib @@ -1 +1 @@ -Subproject commit 051b50ca38ec4c05a11e8216ac259b4488b825f0 +Subproject commit ec4ecacb43d4c12902f4ef9c52f43b1ce122e19e diff --git a/src/main.ts b/src/main.ts index ecfcc37..bceb5a3 100644 --- a/src/main.ts +++ b/src/main.ts @@ -87,7 +87,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin } processReplication = (e: PouchDB.Core.ExistingDocument[]) => this.parseReplicationResult(e); - async connectRemoteCouchDB(uri: string, auth: { username: string; password: string }, disableRequestURI: boolean, passphrase: string | false, useDynamicIterationCount: boolean): Promise; info: PouchDB.Core.DatabaseInfo }> { + async connectRemoteCouchDB(uri: string, auth: { username: string; password: string }, disableRequestURI: boolean, passphrase: string | false, useDynamicIterationCount: boolean, performSetup: boolean, skipInfo: boolean): Promise; info: PouchDB.Core.DatabaseInfo }> { if (!isValidRemoteCouchDBURI(uri)) return "Remote URI is not valid"; if (uri.toLowerCase() != uri) return "Remote URI and database name could not contain capital letters."; if (uri.indexOf(" ") !== -1) return "Remote URI and database name could not contain spaces."; @@ -104,6 +104,7 @@ export default class ObsidianLiveSyncPlugin extends Plugin const conf: PouchDB.HttpAdapter.HttpAdapterConfiguration = { adapter: "http", auth, + skip_setup: !performSetup, fetch: async (url: string | Request, opts: RequestInit) => { let size = ""; const localURL = url.toString().substring(uri.length); @@ -192,6 +193,9 @@ export default class ObsidianLiveSyncPlugin extends Plugin if (passphrase !== "false" && typeof passphrase === "string") { enableEncryption(db, passphrase, useDynamicIterationCount); } + if (skipInfo) { + return { db: db, info: {} }; + } try { const info = await db.info(); return { db: db, info: info }; @@ -1364,8 +1368,8 @@ export default class ObsidianLiveSyncPlugin extends Plugin // If `Read chunks online` is disabled, chunks should be transferred before here. // However, in some cases, chunks are after that. So, if missing chunks exist, we have to wait for them. if ((!this.settings.readChunksOnline) && "children" in doc) { - const c = await this.localDatabase.collectChunksWithCache(doc.children) - const missing = c.filter((e) => !e.chunk).map((e) => e.id); + const c = await this.localDatabase.collectChunksWithCache(doc.children); + const missing = c.filter((e) => e.chunk === false).map((e) => e.id); if (missing.length > 0) Logger(`${path} (${doc._id}, ${doc._rev}) Queued (waiting ${missing.length} items)`, LOG_LEVEL.VERBOSE); newQueue.missingChildren = missing; this.queuedFiles.push(newQueue); @@ -1381,15 +1385,15 @@ export default class ObsidianLiveSyncPlugin extends Plugin const docsSorted = docs.sort((a, b) => b.mtime - a.mtime); L1: for (const change of docsSorted) { + if (isChunk(change._id)) { + await this.parseIncomingChunk(change); + continue; + } for (const proc of this.addOns) { if (await proc.parseReplicationResultItem(change)) { continue L1; } } - if (isChunk(change._id)) { - await this.parseIncomingChunk(change); - continue; - } if (change._id == SYNCINFO_ID) { continue; }