perf: single process event for processSyncActions

This commit is contained in:
Adhiraj Singh
2021-11-25 15:20:47 +05:30
parent f5fcaa36f3
commit a07a63fa28

View File

@@ -228,12 +228,13 @@ export const makeChatsSocket = (config: SocketConfig) => {
if(newMutations.length) { if(newMutations.length) {
logger.trace({ newMutations, name }, 'recv new mutations') logger.trace({ newMutations, name }, 'recv new mutations')
} }
processSyncActions(newMutations)
totalMutations.push(...newMutations) totalMutations.push(...newMutations)
} }
} }
processSyncActions(totalMutations)
return totalMutations return totalMutations
} }
@@ -419,9 +420,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
initial, initial,
authState.keys, authState.keys,
) )
// temp: verify it was encoded correctly
const result = await decodePatches(name, [{ ...patch, version: { version: state.version }, }], initial, authState.keys.getAppStateSyncKey)
const node: BinaryNode = { const node: BinaryNode = {
tag: 'iq', tag: 'iq',
attrs: { attrs: {
@@ -458,6 +457,7 @@ export const makeChatsSocket = (config: SocketConfig) => {
await authState.keys.setAppStateSyncVersion(name, state) await authState.keys.setAppStateSyncVersion(name, state)
if(config.emitOwnEvents) { if(config.emitOwnEvents) {
const result = await decodePatches(name, [{ ...patch, version: { version: state.version }, }], initial, authState.keys.getAppStateSyncKey)
processSyncActions(result.newMutations) processSyncActions(result.newMutations)
} }
} }