Local Storage Cache: Limit users to 5000 to avoid quoate excess

This commit is contained in:
Alexander Zinchuk 2021-04-24 15:15:50 +03:00
parent 76c2ff41ec
commit a20ab4b6aa
2 changed files with 7 additions and 2 deletions

View File

@ -16,6 +16,7 @@ export const GRAMJS_SESSION_ID_KEY = 'GramJs:sessionId';
export const GLOBAL_STATE_CACHE_DISABLED = false;
export const GLOBAL_STATE_CACHE_KEY = 'tt-global-state';
export const GLOBAL_STATE_CACHE_CHAT_LIST_LIMIT = 30;
export const GLOBAL_STATE_CACHE_USER_LIST_LIMIT = 5000;
export const MEDIA_CACHE_DISABLED = false;
export const MEDIA_CACHE_NAME = 'tt-media';

View File

@ -12,7 +12,7 @@ import {
GLOBAL_STATE_CACHE_KEY,
GLOBAL_STATE_CACHE_CHAT_LIST_LIMIT,
GRAMJS_SESSION_ID_KEY,
MIN_SCREEN_WIDTH_FOR_STATIC_RIGHT_COLUMN,
MIN_SCREEN_WIDTH_FOR_STATIC_RIGHT_COLUMN, GLOBAL_STATE_CACHE_USER_LIST_LIMIT,
} from '../config';
import { IS_MOBILE_SCREEN } from '../util/environment';
import { pick } from '../util/iteratees';
@ -123,9 +123,13 @@ function reduceShowChatInfo(global: GlobalState): boolean {
function reduceUsers(global: GlobalState): GlobalState['users'] {
const { users: { byId, selectedId } } = global;
const idsToSave = [
...(global.chats.listIds.active || []).slice(0, GLOBAL_STATE_CACHE_CHAT_LIST_LIMIT).filter((cid) => cid > 0),
...Object.keys(byId),
].slice(0, GLOBAL_STATE_CACHE_USER_LIST_LIMIT);
return {
byId,
byId: pick(byId, idsToSave as number[]),
selectedId: window.innerWidth > MIN_SCREEN_WIDTH_FOR_STATIC_RIGHT_COLUMN ? selectedId : undefined,
};
}