Skip to content

Commit

Permalink
fix: only mark sync state enabled when entire group is enabled (#785)
Browse files Browse the repository at this point in the history
Imagine the following scenario:

- *auth* namespace sync is enabled.
- *config* namespace sync is disabled.
- *blobIndex* namespace sync is enabled.

Previously, this would report the initial namespace sync state as
*enabled*. Now, this will report *disabled*, because every namespace
needs to be on.
  • Loading branch information
EvanHahn authored Aug 29, 2024
1 parent 304eb60 commit ae81496
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/sync/sync-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,9 @@ function getRemoteDevicesSyncState(namespaceSyncState, peerSyncControllers) {
for (const psc of peerSyncControllers) {
const { peerId } = psc

/** @type {undefined | boolean} */ let isInitialEnabled
/** @type {undefined | boolean} */ let isDataEnabled

for (const namespace of NAMESPACES) {
const isBlocked = psc.syncCapability[namespace] === 'blocked'
if (isBlocked) continue
Expand Down Expand Up @@ -552,13 +555,24 @@ function getRemoteDevicesSyncState(namespaceSyncState, peerSyncControllers) {
}
}

const namespaceGroup = PRESYNC_NAMESPACES.includes(namespace)
? 'initial'
: 'data'
result[peerId][namespaceGroup].isSyncEnabled = isSyncEnabled
/** @type {'initial' | 'data'} */ let namespaceGroup
const isPresyncNamespace = PRESYNC_NAMESPACES.includes(namespace)
if (isPresyncNamespace) {
namespaceGroup = 'initial'
isInitialEnabled = (isInitialEnabled ?? true) && isSyncEnabled
} else {
namespaceGroup = 'data'
isDataEnabled = (isDataEnabled ?? true) && isSyncEnabled
}

result[peerId][namespaceGroup].want += peerNamespaceState.want
result[peerId][namespaceGroup].wanted += peerNamespaceState.wanted
}

if (Object.hasOwn(result, peerId)) {
result[peerId].initial.isSyncEnabled = Boolean(isInitialEnabled)
result[peerId].data.isSyncEnabled = Boolean(isDataEnabled)
}
}

return result
Expand Down

0 comments on commit ae81496

Please sign in to comment.