[Perf] Chats: Use deep equal check after detecting language

This commit is contained in:
Alexander Zinchuk 2024-09-06 15:42:52 +02:00
parent a960f3e473
commit 8b717b010f
2 changed files with 11 additions and 3 deletions

View File

@ -2578,7 +2578,7 @@ addActionHandler('updateChatDetectedLanguage', (global, actions, payload): Actio
global = getGlobal();
global = updateChat(global, chatId, {
detectedLanguage,
});
}, undefined, true);
return global;
});

View File

@ -6,7 +6,7 @@ import type { ChatListType, GlobalState } from '../types';
import { ARCHIVED_FOLDER_ID } from '../../config';
import { areDeepEqual } from '../../util/areDeepEqual';
import {
areSortedArraysEqual, buildCollectionByKey, omit, unique,
areSortedArraysEqual, buildCollectionByKey, omit, pick, unique,
} from '../../util/iteratees';
import { selectChat, selectChatFullInfo } from '../selectors';
import { updateThread, updateThreadInfo } from './messages';
@ -157,10 +157,18 @@ export function removeUnreadMentions<T extends GlobalState>(
}
export function updateChat<T extends GlobalState>(
global: T, chatId: string, chatUpdate: Partial<ApiChat>, noOmitUnreadReactionCount = false,
global: T, chatId: string, chatUpdate: Partial<ApiChat>, noOmitUnreadReactionCount = false, withDeepCheck = false,
): T {
const { byId } = global.chats;
const chat = byId[chatId];
if (withDeepCheck && chat) {
const updateKeys = Object.keys(chatUpdate) as (keyof ApiChat)[];
if (areDeepEqual(pick(chat, updateKeys), chatUpdate)) {
return global;
}
}
const updatedChat = getUpdatedChat(global, chatId, chatUpdate, noOmitUnreadReactionCount);
if (!updatedChat) {
return global;