Reduce HTTPS calls for rootId & driveId by using init() set values

* Rather than make repeated HTTPS calls for the OneDrive rootId &
driveId, reuse the rootId & driveId as set via init() where possible
This commit is contained in:
abraunegg 2018-04-21 16:30:35 +10:00
parent 7a394a065f
commit 63f991a64e

View file

@ -171,8 +171,9 @@ final class SyncEngine
void applyDifferences() void applyDifferences()
{ {
// Set defaults for the root folder // Set defaults for the root folder
string driveId = defaultDriveId = onedrive.getDefaultDrive()["id"].str; // Use the global's as initialised via init() rather than performing unnecessary additional HTTPS calls
string rootId = onedrive.getDefaultRoot["id"].str; string driveId = defaultDriveId;
string rootId = defaultRootId;
applyDifferences(driveId, rootId); applyDifferences(driveId, rootId);
// check all remote folders // check all remote folders
@ -201,9 +202,8 @@ final class SyncEngine
// If the OneDrive Root is not in the local database, creating a remote folder will fail // If the OneDrive Root is not in the local database, creating a remote folder will fail
checkDatabaseForOneDriveRoot(); checkDatabaseForOneDriveRoot();
// Configure the defaults // Use the global's as initialised via init() rather than performing unnecessary additional HTTPS calls
defaultDriveId = onedrive.getDefaultDrive()["id"].str; string driveId = defaultDriveId;
string driveId = onedrivePathDetails["parentReference"]["driveId"].str; // Should give something like 12345abcde1234a1
string folderId = onedrivePathDetails["id"].str; // Should give something like 12345ABCDE1234A1!101 string folderId = onedrivePathDetails["id"].str; // Should give something like 12345ABCDE1234A1!101
// Apply any differences found on OneDrive for this path (download data) // Apply any differences found on OneDrive for this path (download data)
@ -248,9 +248,8 @@ final class SyncEngine
// delete a directory on OneDrive without syncing // delete a directory on OneDrive without syncing
auto deleteDirectoryNoSync(string path) auto deleteDirectoryNoSync(string path)
{ {
// Set defaults for the root folder // Use the global's as initialised via init() rather than performing unnecessary additional HTTPS calls
defaultDriveId = onedrive.getDefaultDrive()["id"].str; string rootId = defaultRootId;
string rootId = onedrive.getDefaultRoot["id"].str;
// Attempt to delete the requested path within OneDrive without performing a sync // Attempt to delete the requested path within OneDrive without performing a sync
log.vlog("Attempting to delete the requested path within OneDrive"); log.vlog("Attempting to delete the requested path within OneDrive");
@ -305,8 +304,8 @@ final class SyncEngine
string deltaLink = itemdb.getDeltaLink(driveId, id); string deltaLink = itemdb.getDeltaLink(driveId, id);
log.vlog("Applying changes of Path ID: " ~ id); log.vlog("Applying changes of Path ID: " ~ id);
// Get the OneDrive Root ID // Use the global's as initialised via init() rather than performing unnecessary additional HTTPS calls
string oneDriveRootId = onedrive.getDefaultRoot["id"].str; string oneDriveRootId = defaultRootId;
for (;;) { for (;;) {
try { try {
@ -603,12 +602,6 @@ final class SyncEngine
// Make sure the OneDrive Root is in the database // Make sure the OneDrive Root is in the database
checkDatabaseForOneDriveRoot(); checkDatabaseForOneDriveRoot();
// make sure defaultDriveId is set
if (defaultDriveId == ""){
// defaultDriveId is not set ... odd ..
defaultDriveId = onedrive.getDefaultDrive()["id"].str;
}
// scan for changes // scan for changes
log.vlog("Uploading differences of ", path); log.vlog("Uploading differences of ", path);
Item item; Item item;
@ -750,11 +743,6 @@ final class SyncEngine
if(encodeComponent(path).length < 430){ if(encodeComponent(path).length < 430){
// path is less than 430 characters // path is less than 430 characters
if (defaultDriveId == ""){
// defaultDriveId is not set ... odd ..
defaultDriveId = onedrive.getDefaultDrive()["id"].str;
}
// skip unexisting symbolic links // skip unexisting symbolic links
if (isSymlink(path) && !exists(readLink(path))) { if (isSymlink(path) && !exists(readLink(path))) {
log.vlog("Skipping item - symbolic link: ", path); log.vlog("Skipping item - symbolic link: ", path);
@ -906,11 +894,6 @@ final class SyncEngine
{ {
Item parent; Item parent;
if (defaultDriveId == ""){
// defaultDriveId is not set ... odd ..
defaultDriveId = onedrive.getDefaultDrive()["id"].str;
}
// Check the database for the parent // Check the database for the parent
enforce(itemdb.selectByPath(dirName(path), defaultDriveId, parent), "The parent item is not in the local database"); enforce(itemdb.selectByPath(dirName(path), defaultDriveId, parent), "The parent item is not in the local database");