From 203e37c694c4292135b7b9a627a67fc8f5bd9f8e Mon Sep 17 00:00:00 2001 From: Malik Zulqurnain Date: Thu, 5 Sep 2024 21:17:51 +0500 Subject: [PATCH 1/2] Minimize calls to `/getAddressProfile` for auth user addresses --- .../client/scripts/models/AddressInfo.ts | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/commonwealth/client/scripts/models/AddressInfo.ts b/packages/commonwealth/client/scripts/models/AddressInfo.ts index 2286e555af9..b78cb194b51 100644 --- a/packages/commonwealth/client/scripts/models/AddressInfo.ts +++ b/packages/commonwealth/client/scripts/models/AddressInfo.ts @@ -1,6 +1,8 @@ import type { WalletId, WalletSsoSource } from '@hicommonwealth/shared'; import moment from 'moment'; +import { userStore } from '../state/ui/user'; import Account, { AccountCommunity } from './Account'; +import MinimumProfile from './MinimumProfile'; class AddressInfo extends Account { public readonly userId: number; @@ -24,6 +26,8 @@ class AddressInfo extends Account { ghostAddress?: boolean; lastActive?: string | moment.Moment; }) { + const authUser = userStore.getState(); + const ignoreProfile = userId === authUser.id ? true : false; super({ address, community, @@ -31,7 +35,28 @@ class AddressInfo extends Account { walletId, walletSsoSource, ghostAddress, - ignoreProfile: false, + profile: (() => { + if (!ignoreProfile) return undefined; + + // if this is auth user, use already fetched address/profile data + const foundAddress = authUser.addresses.find( + (a) => + a.address === address && + a.community.id === community.id && + a.profile, + ); + const profile = new MinimumProfile(address, community.id); + profile.initialize( + userId, + '', // user name - not needed for auth user + address, + '', // user avatar url - not needed for auth user + community.id, + foundAddress?.lastActive?.toDate?.() || null, + ); + return profile; + })(), + ignoreProfile, lastActive, }); this.userId = userId; From 157bd7f9474835463c65bbb77686af7d8a797a6b Mon Sep 17 00:00:00 2001 From: Malik Zulqurnain Date: Thu, 5 Sep 2024 23:29:42 +0500 Subject: [PATCH 2/2] Removed unnecessary condition --- packages/commonwealth/client/scripts/models/AddressInfo.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/packages/commonwealth/client/scripts/models/AddressInfo.ts b/packages/commonwealth/client/scripts/models/AddressInfo.ts index b78cb194b51..c65022d8ecb 100644 --- a/packages/commonwealth/client/scripts/models/AddressInfo.ts +++ b/packages/commonwealth/client/scripts/models/AddressInfo.ts @@ -40,10 +40,7 @@ class AddressInfo extends Account { // if this is auth user, use already fetched address/profile data const foundAddress = authUser.addresses.find( - (a) => - a.address === address && - a.community.id === community.id && - a.profile, + (a) => a.address === address && a.community.id === community.id, ); const profile = new MinimumProfile(address, community.id); profile.initialize(