Skip to content

Commit

Permalink
Desktop,Mobile,Cli: Fixes #9800: Fix synchronization happens every 10…
Browse files Browse the repository at this point in the history
… seconds even if nothing has changed (#9814)
  • Loading branch information
personalizedrefrigerator authored Feb 2, 2024
1 parent 7c53997 commit 236d977
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 9 additions & 0 deletions packages/lib/services/synchronizer/syncInfoUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
8 changes: 6 additions & 2 deletions packages/lib/services/synchronizer/syncInfoUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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;
}
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 236d977

Please sign in to comment.