[Perf] Do not load emoji keywords on each chat opening

This commit is contained in:
Alexander Zinchuk 2021-08-03 19:03:08 +03:00
parent 60acbc2f02
commit 69b9394a18
2 changed files with 16 additions and 20 deletions

View File

@ -8,7 +8,7 @@ import { ApiMessage } from '../../api/types';
import '../../modules/actions/all';
import {
ANIMATION_END_DELAY, DEBUG, INACTIVE_MARKER, PAGE_TITLE,
ANIMATION_END_DELAY, BASE_EMOJI_KEYWORD_LANG, DEBUG, INACTIVE_MARKER, PAGE_TITLE,
} from '../../config';
import { pick } from '../../util/iteratees';
import {
@ -36,6 +36,7 @@ import SafeLinkModal from './SafeLinkModal.async';
import HistoryCalendar from './HistoryCalendar.async';
import './Main.scss';
import { LangCode } from '../../types';
type StateProps = {
animationLevel: number;
@ -50,11 +51,12 @@ type StateProps = {
safeLinkModalUrl?: string;
isHistoryCalendarOpen: boolean;
shouldSkipHistoryAnimations?: boolean;
language?: LangCode;
};
type DispatchProps = Pick<GlobalActions, (
'loadAnimatedEmojis' | 'loadNotificationSettings' | 'loadNotificationExceptions' | 'updateIsOnline' |
'loadTopInlineBots'
'loadTopInlineBots' | 'loadEmojiKeywords'
)>;
const ANIMATION_DURATION = 350;
@ -78,11 +80,13 @@ const Main: FC<StateProps & DispatchProps> = ({
safeLinkModalUrl,
isHistoryCalendarOpen,
shouldSkipHistoryAnimations,
language,
loadAnimatedEmojis,
loadNotificationSettings,
loadNotificationExceptions,
updateIsOnline,
loadTopInlineBots,
loadEmojiKeywords,
}) => {
if (DEBUG && !DEBUG_isLogged) {
DEBUG_isLogged = true;
@ -98,10 +102,15 @@ const Main: FC<StateProps & DispatchProps> = ({
loadNotificationSettings();
loadNotificationExceptions();
loadTopInlineBots();
loadEmojiKeywords({ language: BASE_EMOJI_KEYWORD_LANG });
if (language !== BASE_EMOJI_KEYWORD_LANG) {
loadEmojiKeywords({ language });
}
}
}, [
lastSyncTime, loadAnimatedEmojis, loadNotificationExceptions, loadNotificationSettings, updateIsOnline,
loadTopInlineBots,
loadTopInlineBots, loadEmojiKeywords, language,
]);
const {
@ -244,10 +253,11 @@ export default memo(withGlobal(
safeLinkModalUrl: global.safeLinkModalUrl,
isHistoryCalendarOpen: Boolean(global.historyCalendarSelectedAt),
shouldSkipHistoryAnimations: global.shouldSkipHistoryAnimations,
language: global.settings.byKey.language,
};
},
(setGlobal, actions): DispatchProps => pick(actions, [
'loadAnimatedEmojis', 'loadNotificationSettings', 'loadNotificationExceptions', 'updateIsOnline',
'loadTopInlineBots',
'loadTopInlineBots', 'loadEmojiKeywords',
]),
)(Main));

View File

@ -18,7 +18,7 @@ import {
ApiUser,
MAIN_THREAD_ID,
} from '../../../api/types';
import { LangCode, InlineBotSettings } from '../../../types';
import { InlineBotSettings } from '../../../types';
import { BASE_EMOJI_KEYWORD_LANG, EDITABLE_INPUT_ID, SCHEDULED_WHEN_ONLINE } from '../../../config';
import { IS_VOICE_RECORDING_SUPPORTED, IS_SINGLE_COLUMN_LAYOUT, IS_IOS } from '../../../util/environment';
@ -124,7 +124,6 @@ type StateProps = {
lastSyncTime?: number;
contentToBeScheduled?: GlobalState['messages']['contentToBeScheduled'];
shouldSuggestStickers?: boolean;
language: LangCode;
baseEmojiKeywords?: Record<string, string[]>;
emojiKeywords?: Record<string, string[]>;
serverTimeOffset: number;
@ -137,7 +136,7 @@ type DispatchProps = Pick<GlobalActions, (
'sendMessage' | 'editMessage' | 'saveDraft' | 'forwardMessages' |
'clearDraft' | 'showDialog' | 'setStickerSearchQuery' | 'setGifSearchQuery' |
'openPollModal' | 'closePollModal' | 'loadScheduledHistory' | 'openChat' | 'closePaymentModal' |
'clearReceipt' | 'addRecentEmoji' | 'loadEmojiKeywords' | 'sendInlineBotResult'
'clearReceipt' | 'addRecentEmoji' | 'sendInlineBotResult'
)>;
enum MainButtonState {
@ -188,7 +187,6 @@ const Composer: FC<OwnProps & StateProps & DispatchProps> = ({
lastSyncTime,
contentToBeScheduled,
shouldSuggestStickers,
language,
baseEmojiKeywords,
emojiKeywords,
serverTimeOffset,
@ -210,7 +208,6 @@ const Composer: FC<OwnProps & StateProps & DispatchProps> = ({
openChat,
clearReceipt,
addRecentEmoji,
loadEmojiKeywords,
sendInlineBotResult,
}) => {
const lang = useLang();
@ -242,15 +239,6 @@ const Composer: FC<OwnProps & StateProps & DispatchProps> = ({
}
}, [isReady, chatId, loadScheduledHistory, lastSyncTime, threadId]);
useEffect(() => {
if (lastSyncTime && isReady) {
loadEmojiKeywords({ language: BASE_EMOJI_KEYWORD_LANG });
if (language !== BASE_EMOJI_KEYWORD_LANG) {
loadEmojiKeywords({ language });
}
}
}, [loadEmojiKeywords, language, lastSyncTime, isReady]);
useLayoutEffect(() => {
if (!appendixRef.current) return;
@ -1038,7 +1026,6 @@ export default memo(withGlobal<OwnProps>(
isReceiptModalOpen: Boolean(global.payment.receipt),
shouldSuggestStickers: global.settings.byKey.shouldSuggestStickers,
recentEmojis: global.recentEmojis,
language,
baseEmojiKeywords: baseEmojiKeywords ? baseEmojiKeywords.keywords : undefined,
emojiKeywords: emojiKeywords ? emojiKeywords.keywords : undefined,
serverTimeOffset: global.serverTimeOffset,
@ -1062,7 +1049,6 @@ export default memo(withGlobal<OwnProps>(
'loadScheduledHistory',
'openChat',
'addRecentEmoji',
'loadEmojiKeywords',
'sendInlineBotResult',
]),
)(Composer));