diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a0ff16c19..3a6959f512 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Changed + +- Improved the performance of the historical market data table of the admin control panel by counting the market data per asset profile + ## 3.91.0 - 2026-10-23 ### Added 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 fc0d97fa62..a104fd48cc 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 @@ -256,11 +256,6 @@ export class AssetProfilesService { return type; }); - const marketDataItems = await this.prismaService.marketData.groupBy({ - _count: true, - by: ['dataSource', 'symbol'] - }); - if (filterByAssetSubClass) { where.assetSubClass = AssetSubClass[filterByAssetSubClass.id]; } @@ -378,13 +373,12 @@ export class AssetProfilesService { await this.marketDataService.getLatest({ dataSource, symbol }) )?.marketPrice; - const marketDataItemCount = - marketDataItems.find((marketDataItem) => { - return ( - marketDataItem.dataSource === dataSource && - marketDataItem.symbol === symbol - ); - })?._count ?? 0; + const marketDataItemCount = await this.prismaService.marketData.count({ + where: { + dataSource, + symbol + } + }); const sectorsCount = sectors ? Object.keys(sectors).length : 0; @@ -521,11 +515,6 @@ export class AssetProfilesService { private async getAssetProfilesForCurrencies(): Promise { const currencyPairs = this.exchangeRateDataService.getCurrencyPairs(); - const marketDataItems = await this.prismaService.marketData.groupBy({ - _count: true, - by: ['dataSource', 'symbol'] - }); - const assetProfilePromises: Promise[] = currencyPairs.map( async ({ dataSource, symbol }) => { let activitiesCount: EnhancedAssetProfile['activitiesCount'] = 0; @@ -542,13 +531,12 @@ export class AssetProfilesService { await this.marketDataService.getLatest({ dataSource, symbol }) )?.marketPrice; - const marketDataItemCount = - marketDataItems.find((marketDataItem) => { - return ( - marketDataItem.dataSource === dataSource && - marketDataItem.symbol === symbol - ); - })?._count ?? 0; + const marketDataItemCount = await this.prismaService.marketData.count({ + where: { + dataSource, + symbol + } + }); return { activitiesCount,