From edadef52886b5f816bda470903c2caabfee22d5a Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Mon, 29 Jul 2024 14:48:17 +0200 Subject: [PATCH] Unidirectional: Fix full tree loading fallback Signed-off-by: Marcel Klehr --- src/lib/strategies/Default.ts | 18 ++++++++++-------- src/lib/strategies/Unidirectional.ts | 5 +++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/lib/strategies/Default.ts b/src/lib/strategies/Default.ts index 1c031f6a..a1466932 100644 --- a/src/lib/strategies/Default.ts +++ b/src/lib/strategies/Default.ts @@ -323,6 +323,9 @@ export default class SyncProcess { this.localTreeRoot = localTreeRoot } + // Cache tree might not have been initialized and thus have no id + this.cacheTreeRoot.id = this.localTreeRoot.id + if (this.canceled) { throw new CancelledSyncError() } @@ -343,15 +346,11 @@ export default class SyncProcess { if ('loadFolderChildren' in this.server) { Logger.log('Loading sparse tree as necessary') // Load sparse tree - await this.loadChildren(serverTreeRoot, mappingsSnapshot) + await this.loadChildren(serverTreeRoot, mappingsSnapshot, true) } - this.serverTreeRoot = serverTreeRoot } - // Cache tree might not have been initialized and thus have no id - this.cacheTreeRoot.id = this.localTreeRoot.id - // generate hash tables to find items faster Logger.log('Generating indices for local tree') this.localTreeRoot.createIndex() @@ -1180,14 +1179,18 @@ export default class SyncProcess { } } - async loadChildren(serverItem:TItem, mappingsSnapshot:MappingSnapshot):Promise { + async loadChildren( + serverItem:TItem, + mappingsSnapshot:MappingSnapshot, + isRoot = false + ):Promise { if (this.canceled) { throw new CancelledSyncError() } if (!(serverItem instanceof Folder)) return if (!('loadFolderChildren' in this.server)) return let localItem, cacheItem - if (serverItem === this.serverTreeRoot) { + if (isRoot) { localItem = this.localTreeRoot cacheItem = this.cacheTreeRoot } else { @@ -1199,7 +1202,6 @@ export default class SyncProcess { localItem && !(await this.folderHasChanged(localItem, cacheItem, serverItem)) ) { - this.actionsDone += localItem.count() return } Logger.log('LOADCHILDREN', serverItem) diff --git a/src/lib/strategies/Unidirectional.ts b/src/lib/strategies/Unidirectional.ts index d7d3505b..1a5f87b3 100644 --- a/src/lib/strategies/Unidirectional.ts +++ b/src/lib/strategies/Unidirectional.ts @@ -75,8 +75,9 @@ export default class UnidirectionalSyncProcess extends DefaultStrategy { return {localScanResult, serverScanResult} } - async loadChildren() :Promise { - this.serverTreeRoot = await this.server.getBookmarksTree(true) + async loadChildren(serverTreeRoot:Folder) :Promise { + Logger.log('Unidirectional: Loading whole tree') + serverTreeRoot.children = (await this.server.getBookmarksTree(true)).children } async sync(): Promise {