on master help sign in
store: improve point sync naming & performance

syncForeignPoint was just an alias for syncDetails. We remove the alias and use syncDetails directly. syncOwnedPoints fetches details that are *potentially* relevant if we own them, but rather unlikely to become useful unless the user navigates to that point's page. We rename it to syncExtras (though it still syncs the "base" details as well). Additionally, and most importantly, we no longer eagerly fetch the extra details about points when we list them on the Points page. Instead, we now only get those for the points the user actually navigates to. This dramatically reduces the number of requests made when logging into an account with many controlled assets.

commit5eceb4e3e8db74187d738f93340d7f18a3b14ca6 authorfang <git@fang.io> dateThu 24 Jun 2021, 20:08 (5 years ago) parentf6cda0a
7 files changed+18−46
src/components/Passport.js+2−2 src/lib/useSyncPoints.js+6−6 src/store/lib/usePointStore.js+4−21 src/views/Invite/Cohort.js+2−2 src/views/Point.js+2−2 src/views/Points.js−11 src/views/Release/Active.js+2−2
src/components/Passport.js+2−2
@@ -7,7 +7,7 @@ import 'style/anim.css';
77import * as need from 'lib/need';
88import { chunkStr, Matrix, walk, rand } from 'lib/card';
99import usePermissionsForPoint from 'lib/usePermissionsForPoint';
10−import { useSyncOwnedPoints } from 'lib/useSyncPoints';
10+import { useSyncDetails } from 'lib/useSyncPoints';
1111import { buildKeyType } from 'lib/point';
1212
1313import { useWallet } from 'store/wallet';
@@ -212,7 +212,7 @@ const Cell = props => {
212212 *
213213 */
214214function MiniPassport({ point, inverted, ...rest }) {
215− useSyncOwnedPoints([point]);
215+ useSyncDetails([point]);
216216 const { wallet } = useWallet();
217217 const address = need.addressFromWallet(wallet);
218218
src/lib/useSyncPoints.js+6−6
@@ -21,12 +21,12 @@ export const useSyncKnownPoints = buildSyncHook(function() {
2121 return syncKnownPoint;
2222});
2323
24−export const useSyncForeignPoints = buildSyncHook(function() {
25− const { syncForeignPoint } = usePointCache();
26− return syncForeignPoint;
24+export const useSyncDetails = buildSyncHook(function() {
25+ const { syncDetails } = usePointCache();
26+ return syncDetails;
2727});
2828
29−export const useSyncOwnedPoints = buildSyncHook(function() {
30− const { syncOwnedPoint } = usePointCache();
31− return syncOwnedPoint;
29+export const useSyncExtras = buildSyncHook(function() {
30+ const { syncExtras } = usePointCache();
31+ return syncExtras;
3232});
src/store/lib/usePointStore.js+4−21
@@ -20,38 +20,22 @@ export default function usePointStore() {
2020 const { syncResidents, syncResidentCount, ...residents } = useResidents();
2121 const ecliptic = useEclipticOwnerStore();
2222
23− // sync all of the on-chain info required to display a known point
23+ //TODO more appropriately named "syncDates" or similar
2424 const syncKnownPoint = useCallback(
2525 async point => Promise.all([syncBirthday(point), syncRekeyDate(point)]),
2626 [syncBirthday, syncRekeyDate]
2727 );
2828
29− // sync all of the on-chain info required to display a foreign point
30− const syncForeignPoint = useCallback(
31− async point => {
32− syncDetails(point);
33− },
34− [syncDetails]
35− );
36−
37− // sync all of the on-chain info required for a point that the user owns
38− const syncOwnedPoint = useCallback(
29+ const syncExtras = useCallback(
3930 async point =>
4031 Promise.all([
41− syncForeignPoint(point),
4232 syncKnownPoint(point),
4333 //
4434 syncResidentCount(point),
4535 syncDetails(point),
4636 syncInvites(point),
4737 ]),
48− [
49− syncForeignPoint,
50− syncKnownPoint,
51− syncDetails,
52− syncInvites,
53− syncResidentCount,
54− ]
38+ [syncKnownPoint, syncDetails, syncInvites, syncResidentCount]
5539 );
5640
5741 return {
@@ -67,8 +51,7 @@ export default function usePointStore() {
6751 syncInvites,
6852 syncControlledPoints,
6953 syncKnownPoint,
70− syncOwnedPoint,
71− syncForeignPoint,
7254 syncResidents,
55+ syncExtras,
7356 };
7457}
src/views/Invite/Cohort.js+2−2
@@ -26,7 +26,7 @@ import Inviter from 'views/Invite/Inviter';
2626
2727import { ReactComponent as SearchIcon } from 'assets/search.svg';
2828import CopyButton from 'components/CopyButton';
29−import { useSyncForeignPoints } from 'lib/useSyncPoints';
29+import { useSyncDetails } from 'lib/useSyncPoints';
3030import { useNetwork } from 'store/network';
3131import NavHeader from 'components/NavHeader';
3232
@@ -305,7 +305,7 @@ export default function InviteCohort() {
305305
306306 const [selectedInvite, _setSelectedInvite] = useState();
307307
308− useSyncForeignPoints([..._acceptedPoints, ..._pendingPoints]);
308+ useSyncDetails([..._acceptedPoints, ..._pendingPoints]);
309309
310310 const setSelectedInvite = useCallback(
311311 p => _setSelectedInvite(old => (old === p ? null : p)),
src/views/Point.js+2−2
@@ -18,7 +18,7 @@ import { ForwardButton } from 'components/Buttons';
1818
1919import * as need from 'lib/need';
2020import useInvites from 'lib/useInvites';
21−import { useSyncOwnedPoints } from 'lib/useSyncPoints';
21+import { useSyncExtras } from 'lib/useSyncPoints';
2222import useCurrentPermissions from 'lib/useCurrentPermissions';
2323import { useLocalRouter } from 'lib/LocalRouter';
2424
@@ -216,7 +216,7 @@ export default function Point() {
216216 })();
217217
218218 // sync the current cursor
219− useSyncOwnedPoints([point]);
219+ useSyncExtras([point]);
220220
221221 const address = need.addressFromWallet(wallet);
222222
src/views/Points.js−11
@@ -12,7 +12,6 @@ import { useStarReleaseCache } from 'store/starRelease';
1212import * as need from 'lib/need';
1313import { isZeroAddress, abbreviateAddress } from 'lib/wallet';
1414import useIsEclipticOwner from 'lib/useIsEclipticOwner';
15−import { useSyncKnownPoints, useSyncOwnedPoints } from 'lib/useSyncPoints';
1615import useRejectedIncomingPointTransfers from 'lib/useRejectedIncomingPointTransfers';
1716import pluralize from 'lib/pluralize';
1817import newGithubIssueUrl from 'new-github-issue-url';
@@ -203,16 +202,6 @@ export default function Points() {
203202 useEffect(() => {
204203 syncStarReleaseDetails();
205204 }, [syncStarReleaseDetails]);
206− // sync display details for known points
207− useSyncKnownPoints([
208− ...ownedPoints,
209− ...incomingPoints,
210− ...managingPoints,
211− ...votingPoints,
212− ...spawningPoints,
213− ]);
214−
215− useSyncOwnedPoints(ownedPoints);
216205
217206 const goCreateGalaxy = useCallback(() => push(names.CREATE_GALAXY), [
218207 names.CREATE_GALAXY,
src/views/Release/Active.js+2−2
@@ -10,13 +10,13 @@ import { useWallet } from 'store/wallet';
1010
1111import * as need from 'lib/need';
1212import usePermissionsForPoint from 'lib/usePermissionsForPoint';
13−import { useSyncOwnedPoints } from 'lib/useSyncPoints';
13+import { useSyncDetails } from 'lib/useSyncPoints';
1414import { buildKeyType } from 'lib/point';
1515
1616function ActiveViewRow({ point, goPoint }) {
1717 const { wallet } = useWallet();
1818 const address = need.addressFromWallet(wallet);
19− useSyncOwnedPoints([point]);
19+ useSyncDetails([point]);
2020 const permissions = usePermissionsForPoint(address, point);
2121
2222 const keyType = buildKeyType(permissions);