From 3ffc5e054da4f76412a7374f8ca51133b9a9d90a Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 28 Jun 2023 21:42:56 -0500 Subject: [PATCH] Fix performance issue with makeGetAccount --- app/soapbox/selectors/index.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/soapbox/selectors/index.ts b/app/soapbox/selectors/index.ts index e0e605335..de3ad4734 100644 --- a/app/soapbox/selectors/index.ts +++ b/app/soapbox/selectors/index.ts @@ -7,6 +7,7 @@ import { import { createSelector } from 'reselect'; import { getSettings } from 'soapbox/actions/settings'; +import { Entities } from 'soapbox/entity-store/entities'; import { getDomain } from 'soapbox/utils/accounts'; import { validId } from 'soapbox/utils/auth'; import ConfigDB from 'soapbox/utils/config-db'; @@ -16,21 +17,20 @@ import { shouldFilter } from 'soapbox/utils/timelines'; import type { ContextType } from 'soapbox/normalizers/filter'; import type { ReducerChat } from 'soapbox/reducers/chats'; import type { RootState } from 'soapbox/store'; -import type { Filter as FilterEntity, Notification, Status } from 'soapbox/types/entities'; +import type { Account, Filter as FilterEntity, Notification, Status } from 'soapbox/types/entities'; const normalizeId = (id: any): string => typeof id === 'string' ? id : ''; -const getAccountBase = (state: RootState, id: string) => state.accounts.get(id); +const getAccountBase = (state: RootState, id: string) => state.entities[Entities.ACCOUNTS]?.store[id] as Account | undefined; const getAccountRelationship = (state: RootState, id: string) => state.relationships.get(id); export const makeGetAccount = () => { return createSelector([ getAccountBase, getAccountRelationship, - ], (base, relationship) => { - if (!base) return null; - base.relationship = base.relationship ?? relationship; - return base; + ], (account, relationship) => { + if (!account) return null; + return { ...account, relationship }; }); };