mirror of
https://github.com/danog/telegram-tt.git
synced 2024-11-27 04:45:08 +01:00
Local Storage Cache: Limit users to 5000 to avoid quoate excess
This commit is contained in:
parent
76c2ff41ec
commit
a20ab4b6aa
@ -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';
|
||||
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user