From a7ecd74fa4d51d3137d2c0ea49737ebb766ea90a Mon Sep 17 00:00:00 2001 From: zubiden <19638254+zubiden@users.noreply.github.com> Date: Fri, 6 Sep 2024 15:43:36 +0200 Subject: [PATCH] Cache: Slight optimization (#4947) --- src/global/cache.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/global/cache.ts b/src/global/cache.ts index c7183555a..4110a9665 100644 --- a/src/global/cache.ts +++ b/src/global/cache.ts @@ -259,10 +259,10 @@ function updateCache(force?: boolean) { export function forceUpdateCache(noEncrypt = false) { const global = getGlobal(); const { hasPasscode, isScreenLocked } = global.passcode; - const serializedGlobal = serializeGlobal(global); if (hasPasscode) { if (!isScreenLocked && !noEncrypt) { + const serializedGlobal = serializeGlobal(global); void encryptSession(undefined, serializedGlobal); } @@ -390,9 +390,9 @@ function reduceUsers(global: T): GlobalState['users'] { ]).slice(0, GLOBAL_STATE_CACHE_USER_LIST_LIMIT); return { - byId: pick(byId, idsToSave), - statusesById: pick(statusesById, idsToSave), - fullInfoById: pick(fullInfoById, idsToSave), + byId: pickTruthy(byId, idsToSave), + statusesById: pickTruthy(statusesById, idsToSave), + fullInfoById: pickTruthy(fullInfoById, idsToSave), previewMediaByBotId: {}, }; } @@ -436,10 +436,10 @@ function reduceChats(global: T): GlobalState['chats'] { ...global.chats, similarChannelsById: {}, isFullyLoaded: {}, - byId: pick(global.chats.byId, idsToSave), - fullInfoById: pick(global.chats.fullInfoById, idsToSave), + byId: pickTruthy(global.chats.byId, idsToSave), + fullInfoById: pickTruthy(global.chats.fullInfoById, idsToSave), lastMessageIds: { - all: pick(global.chats.lastMessageIds.all || {}, idsToSave), + all: pickTruthy(global.chats.lastMessageIds.all || {}, idsToSave), saved: global.chats.lastMessageIds.saved, }, };