From bb8a5a46fcfed845f4ddce370c5f53c3f4a53db6 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Mon, 5 Oct 2026 21:05:14 +0200 Subject: [PATCH 1/2] Improve performance of last market price in market data table of admin control --- .../asset-profiles/asset-profiles.service.ts | 83 +++---------------- 1 file changed, 10 insertions(+), 73 deletions(-) diff --git a/apps/api/src/app/endpoints/asset-profiles/asset-profiles.service.ts b/apps/api/src/app/endpoints/asset-profiles/asset-profiles.service.ts index 4a2507e697..2aefc4535e 100644 --- a/apps/api/src/app/endpoints/asset-profiles/asset-profiles.service.ts +++ b/apps/api/src/app/endpoints/asset-profiles/asset-profiles.service.ts @@ -334,37 +334,6 @@ export class AssetProfilesService { const symbolProfiles = symbolProfileResult[0]; let count = symbolProfileResult[1]; - const lastMarketPrices = await this.prismaService.marketData.findMany({ - distinct: ['dataSource', 'symbol'], - orderBy: { date: 'desc' }, - select: { - dataSource: true, - marketPrice: true, - symbol: true - }, - where: { - dataSource: { - in: symbolProfiles.map(({ dataSource }) => { - return dataSource; - }) - }, - symbol: { - in: symbolProfiles.map(({ symbol }) => { - return symbol; - }) - } - } - }); - - const lastMarketPriceMap = new Map(); - - for (const { dataSource, marketPrice, symbol } of lastMarketPrices) { - lastMarketPriceMap.set( - getAssetProfileIdentifier({ dataSource, symbol }), - marketPrice - ); - } - const dataProviderInfoMap = new Map( [ ...new Set( @@ -405,9 +374,9 @@ export class AssetProfilesService { const countriesCount = countries ? Object.keys(countries).length : 0; - const lastMarketPrice = lastMarketPriceMap.get( - getAssetProfileIdentifier({ dataSource, symbol }) - ); + const lastMarketPrice = ( + await this.marketDataService.getLatest({ dataSource, symbol }) + )?.marketPrice; const marketDataItemCount = marketDataItems.find((marketDataItem) => { @@ -552,42 +521,10 @@ export class AssetProfilesService { private async getAssetProfilesForCurrencies(): Promise { const currencyPairs = this.exchangeRateDataService.getCurrencyPairs(); - const [lastMarketPrices, marketDataItems] = await Promise.all([ - this.prismaService.marketData.findMany({ - distinct: ['dataSource', 'symbol'], - orderBy: { date: 'desc' }, - select: { - dataSource: true, - marketPrice: true, - symbol: true - }, - where: { - dataSource: { - in: currencyPairs.map(({ dataSource }) => { - return dataSource; - }) - }, - symbol: { - in: currencyPairs.map(({ symbol }) => { - return symbol; - }) - } - } - }), - this.prismaService.marketData.groupBy({ - _count: true, - by: ['dataSource', 'symbol'] - }) - ]); - - const lastMarketPriceMap = new Map(); - - for (const { dataSource, marketPrice, symbol } of lastMarketPrices) { - lastMarketPriceMap.set( - getAssetProfileIdentifier({ dataSource, symbol }), - marketPrice - ); - } + const marketDataItems = await this.prismaService.marketData.groupBy({ + _count: true, + by: ['dataSource', 'symbol'] + }); const assetProfilePromises: Promise[] = currencyPairs.map( async ({ dataSource, symbol }) => { @@ -601,9 +538,9 @@ export class AssetProfilesService { await this.activitiesService.getStatisticsByCurrency(currency)); } - const lastMarketPrice = lastMarketPriceMap.get( - getAssetProfileIdentifier({ dataSource, symbol }) - ); + const lastMarketPrice = ( + await this.marketDataService.getLatest({ dataSource, symbol }) + )?.marketPrice; const marketDataItemCount = marketDataItems.find((marketDataItem) => { From 96d9457e419a5acb547a03d1a0adc1cf4846e12a Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Mon, 5 Oct 2026 21:05:24 +0200 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 366727022c..cb7ee7ce5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Improved the performance of the historical market data table of the admin control panel by loading only the latest market price per asset profile - Deprecated `SymbolProfile` in favor of `assetProfile` in the endpoint `POST api/v1/activities` - Upgraded `Nx` from version `23.1.1` to `23.2.1`