Optimize local first mode

This commit is contained in:
Jcomp 2023-10-20 17:38:42 +00:00
parent 77c294ba0c
commit 613de59e7d
2 changed files with 49 additions and 37 deletions

View file

@ -976,14 +976,7 @@ void performStandardSyncProcess(string localPath, Monitor filesystemMonitor = nu
filesystemMonitor.update(true);
}
// Scan the configured 'sync_dir' for new data to upload to OneDrive
syncEngineInstance.scanLocalFilesystemPathForNewData(localPath);
if (appConfig.getValueBool("monitor")) {
// Handle any new inotify events whilst the local filesystem was being scanned
filesystemMonitor.update(true);
}
// Download data from OneDrive last
// Download data from OneDrive first so that we won't have to check local file one by one first
syncEngineInstance.syncOneDriveAccountToLocalDisk();
if (appConfig.getValueBool("monitor")) {
// Cancel out any inotify events from downloading data
@ -998,42 +991,40 @@ void performStandardSyncProcess(string localPath, Monitor filesystemMonitor = nu
filesystemMonitor.update(false);
}
// Perform the local database consistency check, picking up locally modified data and uploading this to OneDrive
syncEngineInstance.performDatabaseConsistencyAndIntegrityCheck();
if (appConfig.getValueBool("monitor")) {
// Handle any inotify events whilst the DB was being scanned
filesystemMonitor.update(true);
}
// Is --download-only NOT configured?
if (!appConfig.getValueBool("download_only")) {
}
// Is --download-only NOT configured?
if (!appConfig.getValueBool("download_only")) {
// Scan the configured 'sync_dir' for new data to upload to OneDrive
syncEngineInstance.scanLocalFilesystemPathForNewData(localPath);
if (appConfig.getValueBool("monitor")) {
// Handle any new inotify events whilst the local filesystem was being scanned
filesystemMonitor.update(true);
}
// Make sure we sync any DB data to this point, but only if not in --monitor mode
// In --monitor mode, this is handled within the 'loop', based on when the full scan true up is being performed
if (!appConfig.getValueBool("monitor")) {
itemDB.performVacuum();
}
// Perform the final true up scan to ensure we have correctly replicated the current online state locally
if (!appConfig.surpressLoggingOutput) {
log.log("Performing a last examination of the most recent online data within Microsoft OneDrive to complete the reconciliation process");
}
// We pass in the 'appConfig.fullScanTrueUpRequired' value which then flags do we use the configured 'deltaLink'
// If 'appConfig.fullScanTrueUpRequired' is true, we do not use the 'deltaLink' if we are in --monitor mode, thus forcing a full scan true up
syncEngineInstance.syncOneDriveAccountToLocalDisk();
if (appConfig.getValueBool("monitor")) {
// Cancel out any inotify events from downloading data
filesystemMonitor.update(false);
}
// Scan the configured 'sync_dir' for new data to upload to OneDrive
syncEngineInstance.scanLocalFilesystemPathForNewData(localPath);
if (appConfig.getValueBool("monitor")) {
// Handle any new inotify events whilst the local filesystem was being scanned
filesystemMonitor.update(true);
}
// Make sure we sync any DB data to this point, but only if not in --monitor mode
// In --monitor mode, this is handled within the 'loop', based on when the full scan true up is being performed
if (!appConfig.getValueBool("monitor")) {
itemDB.performVacuum();
}
// Perform the final true up scan to ensure we have correctly replicated the current online state locally
if (!appConfig.surpressLoggingOutput) {
log.log("Performing a last examination of the most recent online data within Microsoft OneDrive to complete the reconciliation process");
}
// We pass in the 'appConfig.fullScanTrueUpRequired' value which then flags do we use the configured 'deltaLink'
// If 'appConfig.fullScanTrueUpRequired' is true, we do not use the 'deltaLink' if we are in --monitor mode, thus forcing a full scan true up
syncEngineInstance.syncOneDriveAccountToLocalDisk();
if (appConfig.getValueBool("monitor")) {
// Cancel out any inotify events from downloading data
filesystemMonitor.update(false);
}
}
}

View file

@ -510,6 +510,19 @@ class SyncEngine {
log.vdebug("Perform a Full Scan True-Up: ", appConfig.fullScanTrueUpRequired);
// Fetch the API response of /delta to track changes on OneDrive
fetchOneDriveDeltaAPIResponse(null, null, null);
// Are we doing a --download-only sync?
if (!appConfig.getValueBool("download_only")) {
// Do we have any existing remote items, where the content is not in-sync with local ones, that needs to be uploaded?
if (!databaseItemsWhereContentHasChanged.empty) {
// There are changed local files that were not in DB to upload
log.log("Changed local items to upload to OneDrive: ", databaseItemsWhereContentHasChanged.length);
processChangedLocalItemsToUpload();
}
}
// Cleanup array memory
databaseItemsWhereContentHasChanged = [];
// Process any download activities or cleanup actions
processDownloadActivities();
@ -1629,6 +1642,14 @@ class SyncEngine {
log.vdebug("item details to update/insert: ", newDatabaseItem);
itemDB.upsert(newDatabaseItem);
return;
} else if (appConfig.getValueBool("local_first")) {
// Item is not in database but exists locally
// In local_first mode, upload it instead
log.vdebug("Skipping OneDrive change as this is determined to be unwanted due to local_first is used, upload it instead.");
// save in database for so it can be found for later updates
itemDB.upsert(newDatabaseItem);
databaseItemsWhereContentHasChanged ~= [newDatabaseItem.driveId, newDatabaseItem.id, newItemPath];
return;
} else {
// Item details from OneDrive and local item details in database are NOT in-sync
log.vdebug("The item to sync exists locally but is NOT in the local database - otherwise this would be handled as changed item");