[Perf] Avoid redundant updates of chat and user usernames field
This commit is contained in:
parent
9080082823
commit
c34ef129ec
@ -9,6 +9,7 @@ import {
|
||||
} from '../../util/iteratees';
|
||||
import { selectChat, selectChatListType } from '../selectors';
|
||||
import { updateThread, updateThreadInfo } from './messages';
|
||||
import { areDeepEqual } from '../../util/areDeepEqual';
|
||||
|
||||
export function replaceChatListIds(
|
||||
global: GlobalState,
|
||||
@ -125,15 +126,24 @@ function getUpdatedChat(
|
||||
) {
|
||||
const { byId } = global.chats;
|
||||
const chat = byId[chatId];
|
||||
const shouldOmitMinInfo = chatUpdate.isMin && chat && !chat.isMin;
|
||||
const omitProps: (keyof ApiChat)[] = [];
|
||||
|
||||
const shouldOmitMinInfo = chatUpdate.isMin && chat && !chat.isMin;
|
||||
if (shouldOmitMinInfo) {
|
||||
omitProps.push('isMin', 'accessHash');
|
||||
}
|
||||
|
||||
if (!noOmitUnreadReactionCount) {
|
||||
omitProps.push('unreadReactionsCount');
|
||||
}
|
||||
|
||||
if (areDeepEqual(chat?.usernames, chatUpdate.usernames)) {
|
||||
omitProps.push('usernames');
|
||||
}
|
||||
|
||||
chatUpdate = noOmitUnreadReactionCount
|
||||
? chatUpdate : omit(chatUpdate, ['unreadReactionsCount']);
|
||||
const updatedChat: ApiChat = {
|
||||
...chat,
|
||||
...(shouldOmitMinInfo
|
||||
? omit(chatUpdate, ['isMin', 'accessHash'])
|
||||
: chatUpdate),
|
||||
...omit(chatUpdate, omitProps),
|
||||
...(photo && { photos: [photo, ...(chat.photos || [])] }),
|
||||
};
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@ import type { ApiUser, ApiUserStatus } from '../../api/types';
|
||||
import { omit, pick } from '../../util/iteratees';
|
||||
import { MEMO_EMPTY_ARRAY } from '../../util/memo';
|
||||
import { updateChat } from './chats';
|
||||
import { areDeepEqual } from '../../util/areDeepEqual';
|
||||
|
||||
export function replaceUsers(global: GlobalState, newById: Record<string, ApiUser>): GlobalState {
|
||||
return {
|
||||
@ -109,11 +110,20 @@ export function addUsers(global: GlobalState, newById: Record<string, ApiUser>):
|
||||
function getUpdatedUser(global: GlobalState, userId: string, userUpdate: Partial<ApiUser>) {
|
||||
const { byId } = global.users;
|
||||
const user = byId[userId];
|
||||
const omitProps: (keyof ApiUser)[] = [];
|
||||
|
||||
const shouldOmitMinInfo = userUpdate.isMin && user && !user.isMin;
|
||||
if (shouldOmitMinInfo) {
|
||||
omitProps.push('isMin', 'accessHash');
|
||||
}
|
||||
|
||||
if (areDeepEqual(user?.usernames, userUpdate.usernames)) {
|
||||
omitProps.push('usernames');
|
||||
}
|
||||
|
||||
const updatedUser = {
|
||||
...user,
|
||||
...(shouldOmitMinInfo ? omit(userUpdate, ['isMin', 'accessHash']) : userUpdate),
|
||||
...omit(userUpdate, omitProps),
|
||||
};
|
||||
|
||||
if (!updatedUser.id || !updatedUser.type) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user