From 640f1e56f195fd1c8e0dc74c741c3d8910183c02 Mon Sep 17 00:00:00 2001 From: fyears <1142836+fyears@users.noreply.github.com> Date: Thu, 4 Apr 2024 22:20:36 +0800 Subject: [PATCH] save the writing --- src/sync.ts | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/src/sync.ts b/src/sync.ts index 32b30f6..c9d32a7 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -1120,26 +1120,31 @@ const dispatchOperationToActualV3 = async ( r.decision === "conflict_created_then_do_nothing" || r.decision === "folder_existed_both_then_do_nothing" ) { - // !! we need to upsert the record, + // !! we MIGHT need to upsert the record, // so that next time we can determine the change delta - // if we have prevSync, we store it because it should keep all necessary info - let entity = r.prevSync; - // if we don't have prevSync, we use remote entity AND local mtime - // as if it is "uploaded" - if (entity === undefined && r.remote !== undefined) { - entity = await decryptRemoteEntityInplace(r.remote, cipher); - entity = await fullfillMTimeOfRemoteEntityInplace( - entity, - r.local?.mtimeCli - ); - } - if (entity !== undefined) { - await upsertPrevSyncRecordByVaultAndProfile( - db, - vaultRandomID, - profileID, - entity - ); + + if (r.prevSync !== undefined) { + // if we have prevSync, + // we don't need to do anything, because the record is already there! + } else { + // if we don't have prevSync, we use remote entity AND local mtime + // as if it is "uploaded" + if (r.remote !== undefined) { + let entity = await decryptRemoteEntityInplace(r.remote, cipher); + entity = await fullfillMTimeOfRemoteEntityInplace( + entity, + r.local?.mtimeCli + ); + + if (entity !== undefined) { + await upsertPrevSyncRecordByVaultAndProfile( + db, + vaultRandomID, + profileID, + entity + ); + } + } } } else if ( r.decision === "local_is_modified_then_push" ||