perf: avoid excess memory usage when syncing state

This commit is contained in:
Adhiraj Singh
2022-06-11 20:25:57 +05:30
parent a0548fbc4c
commit f87f89329b
3 changed files with 237 additions and 125 deletions

View File

@@ -1,6 +1,7 @@
import type { proto } from '../../WAProto'
import type { AccountSettings } from './Auth'
import type { MinimalMessage } from './Message'
import type { AccountSettings, AuthenticationCreds } from './Auth'
import { Contact } from './Contact'
import type { MinimalMessage, WAMessageUpdate } from './Message'
/** set of statuses visible to other people; see updatePresence() in WhatsAppWeb.Send */
export type WAPresence = 'unavailable' | 'available' | 'composing' | 'recording' | 'paused'
@@ -25,7 +26,19 @@ export type ChatMutation = {
index: string[]
}
export type AppStateChunk = { totalMutations : ChatMutation[], collectionsToHandle: WAPatchName[] }
export type SyncActionUpdates = {
credsUpdates: Partial<AuthenticationCreds>
chatUpdates: { [jid: string]: Partial<Chat> }
chatDeletes: string[]
contactUpserts: { [jid: string]: Contact }
msgUpdates: { [jid: string]: WAMessageUpdate }
msgDeletes: proto.IMessageKey[]
}
export type AppStateChunk = {
updates: SyncActionUpdates
collectionsToHandle: WAPatchName[]
}
export type WAPatchCreate = {
syncAction: proto.ISyncActionValue
@@ -76,7 +89,6 @@ export type ChatModification =
} |
{ delete: true, lastMessages: LastMessageList }
export type InitialReceivedChatsState = {
[jid: string]: { lastMsgRecvTimestamp: number }
}