From 87d73bf6bc76fe3c3c6a5c7e966557e1353b98ce Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Thu, 27 Jul 2023 11:48:06 +0200 Subject: [PATCH] [Perf] Fix broken `addUsers/addChats` optimization (follow-up) --- src/global/reducers/chats.ts | 8 +++++--- src/global/reducers/users.ts | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/global/reducers/chats.ts b/src/global/reducers/chats.ts index 505f097b7..def35cf03 100644 --- a/src/global/reducers/chats.ts +++ b/src/global/reducers/chats.ts @@ -1,6 +1,6 @@ import type { GlobalState } from '../types'; import type { - ApiChat, ApiChatMember, ApiTopic, ApiPhoto, ApiChatFullInfo, + ApiChat, ApiChatFullInfo, ApiChatMember, ApiPhoto, ApiTopic, } from '../../api/types'; import { ARCHIVED_FOLDER_ID } from '../../config'; @@ -142,11 +142,13 @@ export function addChats(global: T, newById: Record>((acc, id) => { const existingChat = byId[id]; - if (existingChat && !existingChat.isMin) { + const newChat = newById[id]; + + if (existingChat && !existingChat.isMin && (newChat.isMin || existingChat.accessHash === newChat.accessHash)) { return acc; } - const updatedChat = getUpdatedChat(global, id, newById[id]); + const updatedChat = getUpdatedChat(global, id, newChat); if (updatedChat) { acc[id] = updatedChat; if (!isUpdated) { diff --git a/src/global/reducers/users.ts b/src/global/reducers/users.ts index 686032de6..555b919e1 100644 --- a/src/global/reducers/users.ts +++ b/src/global/reducers/users.ts @@ -84,11 +84,13 @@ export function addUsers(global: T, newById: Record>((acc, id) => { const existingUser = byId[id]; - if (existingUser && !existingUser.isMin) { + const newUser = newById[id]; + + if (existingUser && !existingUser.isMin && (newUser.isMin || existingUser.accessHash === newUser.accessHash)) { return acc; } - const updatedUser = getUpdatedUser(global, id, newById[id]); + const updatedUser = getUpdatedUser(global, id, newUser); if (updatedUser) { acc[id] = updatedUser; if (!isUpdated) {