From 236d977c415700a2de8075e6c107453277c83c1e Mon Sep 17 00:00:00 2001 From: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com> Date: Fri, 2 Feb 2024 09:53:22 -0800 Subject: [PATCH] Desktop,Mobile,Cli: Fixes #9800: Fix synchronization happens every 10 seconds even if nothing has changed (#9814) --- packages/lib/services/synchronizer/syncInfoUtils.test.ts | 9 +++++++++ packages/lib/services/synchronizer/syncInfoUtils.ts | 8 ++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/packages/lib/services/synchronizer/syncInfoUtils.test.ts b/packages/lib/services/synchronizer/syncInfoUtils.test.ts index ea796e01349..869408b6fa2 100644 --- a/packages/lib/services/synchronizer/syncInfoUtils.test.ts +++ b/packages/lib/services/synchronizer/syncInfoUtils.test.ts @@ -105,6 +105,15 @@ describe('syncInfoUtils', () => { syncInfo1.appMinVersion = '1.0.0'; syncInfo2.appMinVersion = '1.0.0'; expect(mergeSyncInfos(syncInfo1, syncInfo2).appMinVersion).toBe('1.0.0'); + + // Should prefer the version from syncInfo1 if versions are otherwise equal. + syncInfo1.appMinVersion = '1.00'; + syncInfo2.appMinVersion = '1.0.0'; + expect(mergeSyncInfos(syncInfo1, syncInfo2).appMinVersion).toBe('1.00'); + + syncInfo1.appMinVersion = '0.0.0'; + syncInfo2.appMinVersion = '0.00'; + expect(mergeSyncInfos(syncInfo1, syncInfo2).appMinVersion).toBe('0.0.0'); }); it('should merge sync target info and takes into account usage of master key - 1', async () => { diff --git a/packages/lib/services/synchronizer/syncInfoUtils.ts b/packages/lib/services/synchronizer/syncInfoUtils.ts index b4f565e4605..2042aaf02c6 100644 --- a/packages/lib/services/synchronizer/syncInfoUtils.ts +++ b/packages/lib/services/synchronizer/syncInfoUtils.ts @@ -178,6 +178,7 @@ const mergeActiveMasterKeys = (s1: SyncInfo, s2: SyncInfo, output: SyncInfo) => } }; +// If there is a distinction, s1 should be local sync info and s2 remote. export function mergeSyncInfos(s1: SyncInfo, s2: SyncInfo): SyncInfo { const output: SyncInfo = new SyncInfo(); @@ -199,7 +200,10 @@ export function mergeSyncInfos(s1: SyncInfo, s2: SyncInfo): SyncInfo { } } - output.appMinVersion = compareVersions(s1.appMinVersion, s2.appMinVersion) > 0 ? s1.appMinVersion : s2.appMinVersion; + // We use >= so that the version from s1 (local) is preferred to the version in s2 (remote). + // For example, if s2 has appMinVersion 0.00 and s1 has appMinVersion 0.0.0, we choose the + // local version, 0.0.0. + output.appMinVersion = compareVersions(s1.appMinVersion, s2.appMinVersion) >= 0 ? s1.appMinVersion : s2.appMinVersion; return output; } @@ -247,7 +251,7 @@ export class SyncInfo { this.activeMasterKeyId_ = 'activeMasterKeyId' in s ? s.activeMasterKeyId : { value: '', updatedTime: 0 }; this.masterKeys_ = 'masterKeys' in s ? s.masterKeys : []; this.ppk_ = 'ppk' in s ? s.ppk : { value: null, updatedTime: 0 }; - this.appMinVersion_ = s.appMinVersion ? s.appMinVersion : '0.00'; + this.appMinVersion_ = s.appMinVersion ? s.appMinVersion : '0.0.0'; // Migration for master keys that didn't have "hasBeenUsed" property - // in that case we assume they've been used at least once.