Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3263350
D8248.id27864.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D8248.id27864.diff
View Options
diff --git a/lib/selectors/nav-selectors.js b/lib/selectors/nav-selectors.js
--- a/lib/selectors/nav-selectors.js
+++ b/lib/selectors/nav-selectors.js
@@ -3,7 +3,7 @@
import * as React from 'react';
import { createSelector } from 'reselect';
-import { useENSNames } from '../hooks/ens-cache.js';
+import { ENSCacheContext } from '../components/ens-cache-provider.react.js';
import SearchIndex from '../shared/search-index.js';
import { memberHasAdminPowers } from '../shared/thread-utils.js';
import type { Platform } from '../types/device-types.js';
@@ -16,6 +16,7 @@
import type { BaseAppState } from '../types/redux-types.js';
import type { RawThreadInfo, ThreadInfo } from '../types/thread-types.js';
import { getConfig } from '../utils/config.js';
+import { getENSNames } from '../utils/ens-helpers.js';
import { values } from '../utils/objects.js';
import { useSelector } from '../utils/redux-utils.js';
@@ -100,14 +101,34 @@
return [...allMembersOfAllThreads.values()];
}, [threadInfos, userInfos, viewerID]);
- const nonViewerMembersWithENSNames = useENSNames(nonViewerMembers);
+ const cacheContext = React.useContext(ENSCacheContext);
+ const { ensCache } = cacheContext;
+
+ // We avoid using useENSNames here because the SearchIndex memo below is very
+ // expensive. useENSNames would trigger its recalculation for each ENS name as
+ // it streams in, but we would prevent to trigger its recaculation just once
+ // for every update of the underlying Redux data.
+ const [nonViewerMembersWithENSNames, setNonViewerMembersWithENSNames] =
+ React.useState();
+ React.useEffect(() => {
+ if (!ensCache) {
+ return;
+ }
+ (async () => {
+ const withENSNames = await getENSNames(ensCache, nonViewerMembers);
+ setNonViewerMembersWithENSNames(withENSNames);
+ })();
+ }, [ensCache, nonViewerMembers]);
+
+ const resolvedNonViewerMembers =
+ nonViewerMembersWithENSNames ?? nonViewerMembers;
const memberMap = React.useMemo(() => {
const result = new Map();
- for (const userInfo of nonViewerMembersWithENSNames) {
+ for (const userInfo of resolvedNonViewerMembers) {
result.set(userInfo.id, userInfo);
}
return result;
- }, [nonViewerMembersWithENSNames]);
+ }, [resolvedNonViewerMembers]);
return React.useMemo(() => {
const searchIndex = new SearchIndex();
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 17, 12:05 AM (20 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2508164
Default Alt Text
D8248.id27864.diff (2 KB)
Attached To
Mode
D8248: [lib] Fix useThreadSearchIndex performance issue
Attached
Detach File
Event Timeline
Log In to Comment