Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance: reduce SearchForReport requests #41729

Merged
merged 4 commits into from
May 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions src/pages/ChatFinderPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {StackScreenProps} from '@react-navigation/stack';
import isEmpty from 'lodash/isEmpty';
import React, {useEffect, useMemo, useState} from 'react';
import React, {useCallback, useEffect, useMemo, useState} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
Expand Down Expand Up @@ -63,15 +63,23 @@ function ChatFinderPage({betas, isSearchingForReports, navigation}: ChatFinderPa
const offlineMessage: MaybePhraseKey = isOffline ? [`${translate('common.youAppearToBeOffline')} ${translate('search.resultsAreLimited')}`, {isTranslated: true}] : '';

const [searchValue, debouncedSearchValue, setSearchValue] = useDebouncedState('');
const [, debouncedSearchValueInServer, setSearchValueInServer] = useDebouncedState('', 500);
const updateSearchValue = useCallback(
(value: string) => {
setSearchValue(value);
setSearchValueInServer(value);
},
[setSearchValue, setSearchValueInServer],
);

useEffect(() => {
Timing.start(CONST.TIMING.CHAT_FINDER_RENDER);
Performance.markStart(CONST.TIMING.CHAT_FINDER_RENDER);
}, []);

useEffect(() => {
Report.searchInServer(debouncedSearchValue.trim());
}, [debouncedSearchValue]);
Report.searchInServer(debouncedSearchValueInServer.trim());
}, [debouncedSearchValueInServer]);

const searchOptions = useMemo(() => {
if (!areOptionsInitialized || !isScreenTransitionEnd) {
Expand Down Expand Up @@ -146,7 +154,7 @@ function ChatFinderPage({betas, isSearchingForReports, navigation}: ChatFinderPa
}

if (option.reportID) {
setSearchValue('');
updateSearchValue('');
Navigation.dismissModal(option.reportID);
} else {
Report.navigateToAndOpenReport(option.login ? [option.login] : []);
Expand Down Expand Up @@ -177,7 +185,7 @@ function ChatFinderPage({betas, isSearchingForReports, navigation}: ChatFinderPa
textInputValue={searchValue}
textInputLabel={translate('optionsSelector.nameEmailOrPhoneNumber')}
textInputHint={offlineMessage}
onChangeText={setSearchValue}
onChangeText={updateSearchValue}
headerMessage={headerMessage}
headerMessageStyle={headerMessage === translate('common.noResultsFound') ? [themeStyles.ph4, themeStyles.pb5] : undefined}
onLayout={setPerformanceTimersEnd}
Expand Down
Loading