mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
perf: put main app state sync in transaction
This commit is contained in:
@@ -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)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user