[Perf] Fix broken addUsers/addChats optimization

This commit is contained in:
Alexander Zinchuk 2023-07-23 10:08:11 +02:00
parent 3b17344a1a
commit c986ea7953
2 changed files with 13 additions and 1 deletions

View File

@ -141,6 +141,11 @@ export function addChats<T extends GlobalState>(global: T, newById: Record<strin
let isUpdated = false;
const addedById = Object.keys(newById).reduce<Record<string, ApiChat>>((acc, id) => {
const existingChat = byId[id];
if (existingChat && !existingChat.isMin) {
return acc;
}
const updatedChat = getUpdatedChat(global, id, newById[id]);
if (updatedChat) {
acc[id] = updatedChat;
@ -148,6 +153,7 @@ export function addChats<T extends GlobalState>(global: T, newById: Record<strin
isUpdated = true;
}
}
return acc;
}, {});

View File

@ -1,4 +1,4 @@
import type { TabState, GlobalState, TabArgs } from '../types';
import type { GlobalState, TabArgs, TabState } from '../types';
import type { ApiUser, ApiUserFullInfo, ApiUserStatus } from '../../api/types';
import { omit, pick } from '../../util/iteratees';
@ -83,6 +83,11 @@ export function addUsers<T extends GlobalState>(global: T, newById: Record<strin
let isUpdated = false;
const addedById = Object.keys(newById).reduce<Record<string, ApiUser>>((acc, id) => {
const existingUser = byId[id];
if (existingUser && !existingUser.isMin) {
return acc;
}
const updatedUser = getUpdatedUser(global, id, newById[id]);
if (updatedUser) {
acc[id] = updatedUser;
@ -90,6 +95,7 @@ export function addUsers<T extends GlobalState>(global: T, newById: Record<strin
isUpdated = true;
}
}
return acc;
}, {});