Page MenuHomePhabricator

D9621.id32666.diff
No OneTemporary

D9621.id32666.diff

diff --git a/lib/selectors/keyserver-selectors.js b/lib/selectors/keyserver-selectors.js
--- a/lib/selectors/keyserver-selectors.js
+++ b/lib/selectors/keyserver-selectors.js
@@ -1,5 +1,6 @@
// @flow
+import _memoize from 'lodash/memoize.js';
import { createSelector } from 'reselect';
import type { PlatformDetails } from '../types/device-types';
@@ -48,12 +49,18 @@
state: AppState,
) => state.keyserverStore.keyserverInfos[ashoatKeyserverID]?.connection;
-const lastCommunicatedPlatformDetailsSelector: (
- state: AppState,
-) => ?PlatformDetails = (state: AppState) =>
- state.keyserverStore.keyserverInfos[ashoatKeyserverID]
+const baseLastCommunicatedPlatformDetailsSelector: (
+ keyserverID: string,
+) => (state: AppState) => ?PlatformDetails = keyserverID => (state: AppState) =>
+ state.keyserverStore.keyserverInfos[keyserverID]
?.lastCommunicatedPlatformDetails;
+const lastCommunicatedPlatformDetailsSelector: (
+ id: string,
+) => (state: AppState) => ?PlatformDetails = _memoize(
+ baseLastCommunicatedPlatformDetailsSelector,
+);
+
const selectedKeyserversSelector: (
state: AppState,
) => $ReadOnlyArray<SelectedKeyserverInfo> = createSelector(
diff --git a/lib/selectors/server-calls.js b/lib/selectors/server-calls.js
--- a/lib/selectors/server-calls.js
+++ b/lib/selectors/server-calls.js
@@ -1,5 +1,6 @@
// @flow
+import _memoize from 'lodash/memoize.js';
import { createSelector } from 'reselect';
import {
@@ -26,14 +27,16 @@
+lastCommunicatedPlatformDetails: ?PlatformDetails,
};
-const serverCallStateSelector: (state: AppState) => ServerCallState =
+const baseServerCallStateSelector: (
+ keyserverID: string,
+) => (state: AppState) => ServerCallState = keyserverID =>
createSelector(
cookieSelector,
urlPrefixSelector,
sessionIDSelector,
(state: AppState) => state.currentUserInfo,
connectionSelector,
- lastCommunicatedPlatformDetailsSelector,
+ lastCommunicatedPlatformDetailsSelector(keyserverID),
(
cookie: ?string,
urlPrefix: ?string,
@@ -51,4 +54,10 @@
}),
);
+const serverCallStateSelector: (
+ id: string,
+) => (state: AppState) => ServerCallState = _memoize(
+ baseServerCallStateSelector,
+);
+
export { serverCallStateSelector };
diff --git a/lib/utils/action-utils.js b/lib/utils/action-utils.js
--- a/lib/utils/action-utils.js
+++ b/lib/utils/action-utils.js
@@ -12,6 +12,7 @@
CallServerEndpointOptions,
} from './call-server-endpoint.js';
import { getConfig } from './config.js';
+import { ashoatKeyserverID } from './validation-utils.js';
import { serverCallStateSelector } from '../selectors/server-calls.js';
import {
logInActionSources,
@@ -436,7 +437,9 @@
paramOverride?: ?$Shape<BindServerCallsParams>,
): F {
const dispatch = useDispatch();
- const serverCallState = useSelector(serverCallStateSelector);
+ const serverCallState = useSelector(
+ serverCallStateSelector(ashoatKeyserverID),
+ );
return React.useMemo(() => {
const { urlPrefix, connectionStatus } = serverCallState;
invariant(
diff --git a/native/socket.react.js b/native/socket.react.js
--- a/native/socket.react.js
+++ b/native/socket.react.js
@@ -21,6 +21,7 @@
useDispatchActionPromise,
fetchNewCookieFromNativeCredentials,
} from 'lib/utils/action-utils.js';
+import { ashoatKeyserverID } from 'lib/utils/validation-utils.js';
import { InputStateContext } from './input/input-state.js';
import {
@@ -102,7 +103,7 @@
}, [active, navContext]);
const lastCommunicatedPlatformDetails = useSelector(
- lastCommunicatedPlatformDetailsSelector,
+ lastCommunicatedPlatformDetailsSelector(ashoatKeyserverID),
);
const dispatch = useDispatch();
diff --git a/web/socket.react.js b/web/socket.react.js
--- a/web/socket.react.js
+++ b/web/socket.react.js
@@ -17,6 +17,7 @@
useServerCall,
useDispatchActionPromise,
} from 'lib/utils/action-utils.js';
+import { ashoatKeyserverID } from 'lib/utils/validation-utils.js';
import { useSelector } from './redux/redux-utils.js';
import {
@@ -67,7 +68,7 @@
const callLogOut = useServerCall(logOut);
const lastCommunicatedPlatformDetails = useSelector(
- lastCommunicatedPlatformDetailsSelector,
+ lastCommunicatedPlatformDetailsSelector(ashoatKeyserverID),
);
return (

File Metadata

Mime Type
text/plain
Expires
Sat, Nov 9, 8:46 AM (20 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2451014
Default Alt Text
D9621.id32666.diff (4 KB)

Event Timeline