Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Task/improve performance of latest market data (#8059)
Thomas Kaul1f9c3dd2f466
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 366727022c..a1fdd458a2 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 getting the latest market data by optimizing the indexes of the market data table- Deprecated `SymbolProfile` in favor of `assetProfile` in the endpoint `POST api/v1/activities`- Upgraded `Nx` from version `23.1.1` to `23.2.1`diff --git a/apps/api/src/services/market-data/market-data.service.ts b/apps/api/src/services/market-data/market-data.service.tsindex e608decca2..c1a31ce815 100644--- a/apps/api/src/services/market-data/market-data.service.ts+++ b/apps/api/src/services/market-data/market-data.service.ts@@ -248,7 +248,7 @@ export class MarketDataService {state: state as MarketDataState},where: {- dataSource_date_symbol: {+ dataSource_symbol_date: {dataSource: dataSource as DataSource,date: date as Date,symbol: symbol as stringdiff --git a/apps/api/src/services/queues/data-gathering/data-gathering.service.ts b/apps/api/src/services/queues/data-gathering/data-gathering.service.tsindex 1162143421..2897855b01 100644--- a/apps/api/src/services/queues/data-gathering/data-gathering.service.ts+++ b/apps/api/src/services/queues/data-gathering/data-gathering.service.ts@@ -348,7 +348,7 @@ export class DataGatheringService {},update: { marketPrice, isCarriedForward: false },where: {- dataSource_date_symbol: {+ dataSource_symbol_date: {dataSource,symbol,date: startOfUtcDatediff --git a/prisma/migrations/20261005000000_updated_indexes_of_market_data/migration.sql b/prisma/migrations/20261005000000_updated_indexes_of_market_data/migration.sqlnew file mode 100644index 0000000000..4dc77ce0ff--- /dev/null+++ b/prisma/migrations/20261005000000_updated_indexes_of_market_data/migration.sql@@ -0,0 +1,8 @@+-- CreateIndex+CREATE UNIQUE INDEX "MarketData_dataSource_symbol_date_key" ON "MarketData"("dataSource", "symbol", "date");++-- DropIndex+DROP INDEX "MarketData_dataSource_symbol_idx";++-- DropIndex+DROP INDEX "MarketData_dataSource_date_symbol_key";diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex d2181e13be..37a3506610 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -173,9 +173,8 @@ model MarketData {state MarketDataState @default(CLOSE)symbol String- @@unique([dataSource, date, symbol])+ @@unique([dataSource, symbol, date])@@index([dataSource])- @@index([dataSource, symbol])@@index([date])@@index([state])@@index([symbol])