From 25d2c9aa982ebdc3cecf2882c390f0291b97dc20 Mon Sep 17 00:00:00 2001 From: jaredvu Date: Wed, 15 Jan 2025 09:12:13 -0800 Subject: [PATCH] weakmapmemoize --- src/abacus-ts/calculators/subaccount.ts | 27 ++++++++++++++----------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/abacus-ts/calculators/subaccount.ts b/src/abacus-ts/calculators/subaccount.ts index 90385a469..0c4b324b1 100644 --- a/src/abacus-ts/calculators/subaccount.ts +++ b/src/abacus-ts/calculators/subaccount.ts @@ -1,5 +1,6 @@ import BigNumber from 'bignumber.js'; import { groupBy, map, mapValues, orderBy, pickBy } from 'lodash'; +import { weakMapMemoize } from 'reselect'; import { NUM_PARENT_SUBACCOUNTS } from '@/constants/account'; import { @@ -296,18 +297,20 @@ function calculatePositionDerivedExtra( }; } -export function calculateChildSubaccountSummaries( - parent: Omit, - markets: MarketsData -): Record { - return pickBy( - mapValues( - parent.childSubaccounts, - (subaccount) => subaccount && calculateSubaccountSummary(subaccount, markets) - ), - isTruthy - ); -} +export const calculateChildSubaccountSummaries = weakMapMemoize( + ( + parent: Omit, + markets: MarketsData + ): Record => { + return pickBy( + mapValues( + parent.childSubaccounts, + (subaccount) => subaccount && calculateSubaccountSummary(subaccount, markets) + ), + isTruthy + ); + } +); /** * @returns a list of pending isolated positions