From 585b35724ffb4ddc2b7097df191bdc25e22fa690 Mon Sep 17 00:00:00 2001 From: abraunegg Date: Wed, 23 Oct 2019 05:29:11 +1100 Subject: [PATCH] Reduce change scan impact of fix for #658 (#691) * If there are delta changes (meaning something changed on OneDrive) process the changes that have been presented --- src/main.d | 1 + src/sync.d | 50 +++++++++++++++++++++++++++++++++----------------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/main.d b/src/main.d index 2a40237c..80d514f9 100644 --- a/src/main.d +++ b/src/main.d @@ -843,6 +843,7 @@ void performSync(SyncEngine sync, string singleDirectory, bool downloadOnly, boo } else { // sync from OneDrive first before uploading files to OneDrive if (logLevel < MONITOR_LOG_SILENT) log.log("Syncing changes from OneDrive ..."); + // if sync_list is configured, syncListConfigured = true, thus a FULL walk of all OneDrive objects will be performed sync.applyDifferences(syncListConfigured); // Is a full scan of the entire sync_dir required? if (fullScanRequired) { diff --git a/src/sync.d b/src/sync.d index b8649998..a1b60892 100644 --- a/src/sync.d +++ b/src/sync.d @@ -591,22 +591,7 @@ final class SyncEngine { log.vlog("Applying changes of Path ID: " ~ id); JSONValue changes; - - // If we are using a sync_list file, using deltaLink will actually 'miss' changes (moves & deletes) on OneDrive as using sync_list discards changes - // Use the performFullItemScan boolean to control whether we perform a full object scan of use the delta link for the root folder - // When using --synchronize the process order is: - // 1. Scan OneDrive for changes - // 2. Scan local folder for changes - // 3. Scan OneDrive for changes - // When using sync_list and performing a full scan, what this means is a full scan is performed twice, which leads to massive processing & time overheads - // Control this via performFullItemScan - - string deltaLink = ""; - if (!performFullItemScan){ - // performFullItemScan == false - // use delta link - deltaLink = itemdb.getDeltaLink(driveId, id); - } + JSONValue changesAvailable; // Query the name of this folder id string syncFolderName; @@ -748,6 +733,24 @@ final class SyncEngine log.vdebug("onedrive.getPathDetailsById call returned an invalid JSON Object"); } + // If we are using a sync_list file, using deltaLink will actually 'miss' changes (moves & deletes) on OneDrive as using sync_list discards changes + // Use the performFullItemScan boolean to control whether we perform a full object scan of use the delta link for the root folder + // When using --synchronize the process order is: + // 1. Scan OneDrive for changes + // 2. Scan local folder for changes + // 3. Scan OneDrive for changes + // When using sync_list and performing a full scan, what this means is a full scan is performed twice, which leads to massive processing & time overheads + // Control this via performFullItemScan + + // Get the current delta link + string deltaLink = ""; + string deltaLinkAvailable = itemdb.getDeltaLink(driveId, id); + if (!performFullItemScan){ + // performFullItemScan == false + // use delta link + deltaLink = deltaLinkAvailable; + } + for (;;) { // Due to differences in OneDrive API's between personal and business we need to get changes only from defaultRootId // If we used the 'id' passed in & when using --single-directory with a business account we get: @@ -767,6 +770,7 @@ final class SyncEngine try { // Fetch the changes relative to the path id we want to query changes = onedrive.viewChangesById(driveId, idToQuery, deltaLink); + changesAvailable = onedrive.viewChangesById(driveId, idToQuery, deltaLinkAvailable); } catch (OneDriveException e) { // OneDrive threw an error log.vdebug("OneDrive threw an error when querying for these changes:"); @@ -811,10 +815,19 @@ final class SyncEngine } } + // is changesAvailable a valid JSON response + long deltaChanges = 0; + if (changesAvailable.type() == JSONType.object) { + // are there any delta changes? + if (("value" in changesAvailable) != null) { + deltaChanges = count(changesAvailable["value"].array); + } + } + // is changes a valid JSON response if (changes.type() == JSONType.object) { // Are there any changes to process? - if (("value" in changes) != null) { + if ((("value" in changes) != null) && (deltaChanges > 0)) { auto nrChanges = count(changes["value"].array); auto changeCount = 0; @@ -1006,6 +1019,9 @@ final class SyncEngine } } } + } else { + // No changes reported on OneDrive + log.vdebug("OneDrive Reported no delta changes - Local path and OneDrive in-sync"); } // the response may contain either @odata.deltaLink or @odata.nextLink