perf: put main app state sync in transaction

This commit is contained in:
Adhiraj Singh
2021-12-12 11:26:19 +05:30
parent 5624ecf96c
commit a21e3b0bac

View File

@@ -178,6 +178,10 @@ export const makeChatsSocket = (config: SocketConfig) => {
const resyncAppStateInternal = async(collections: WAPatchName[], fromScratch: boolean = false, returnSnapshot: boolean = false) => { const resyncAppStateInternal = async(collections: WAPatchName[], fromScratch: boolean = false, returnSnapshot: boolean = false) => {
if(fromScratch) returnSnapshot = true if(fromScratch) returnSnapshot = true
const totalMutations: ChatMutation[] = []
await authState.keys.transaction(
async() => {
const states = { } as { [T in WAPatchName]: LTHashState } const states = { } as { [T in WAPatchName]: LTHashState }
for(const name of collections) { for(const name of collections) {
let state: LTHashState let state: LTHashState
@@ -217,7 +221,6 @@ export const makeChatsSocket = (config: SocketConfig) => {
}) })
const decoded = await extractSyncdPatches(result) // extract from binary node const decoded = await extractSyncdPatches(result) // extract from binary node
const totalMutations: ChatMutation[] = []
for(const key in decoded) { for(const key in decoded) {
const name = key as WAPatchName const name = key as WAPatchName
const { patches, snapshot } = decoded[name] const { patches, snapshot } = decoded[name]
@@ -241,6 +244,8 @@ export const makeChatsSocket = (config: SocketConfig) => {
totalMutations.push(...newMutations) totalMutations.push(...newMutations)
} }
} }
}
)
processSyncActions(totalMutations) processSyncActions(totalMutations)