Browse Source

Task/improve performance of historical market data query (#8061)

* Improve performance of historical market data query

* Update changelog
pull/8109/head
Thomas Kaul 10 hours ago
committed by GitHub
parent
commit
3ecf11bb98
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 11
      apps/api/src/services/data-provider/data-provider.service.ts

1
CHANGELOG.md

@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Extended the benchmark comparator to support benchmarks whose market data starts later than the portfolio
- Harmonized the colors in the investment chart component
- Improved the performance of getting the historical market data by loading only the requested asset profiles
- Improved the language localization for Chinese (`zh`)
### Fixed

11
apps/api/src/services/data-provider/data-provider.service.ts

@ -403,12 +403,8 @@ export class DataProviderService implements OnModuleInit {
})}::timestamp`
: Prisma.empty;
const dataSources = aItems.map(({ dataSource }) => {
return dataSource;
});
const symbols = aItems.map(({ symbol }) => {
return symbol;
const assetProfileIdentifiers = aItems.map(({ dataSource, symbol }) => {
return Prisma.sql`(${dataSource}::"DataSource", ${symbol})`;
});
try {
@ -416,8 +412,7 @@ export class DataProviderService implements OnModuleInit {
.$queryRaw`
SELECT *
FROM "MarketData"
WHERE "dataSource"::text IN (${Prisma.join(dataSources)})
AND "symbol" IN (${Prisma.join(symbols)})
WHERE ("dataSource", "symbol") IN (${Prisma.join(assetProfileIdentifiers)})
${granularityQuery}
${rangeQuery}
ORDER BY date;`;

Loading…
Cancel
Save