From cfc873f69ed7b05b02cc13265cfcd9e62eeafe15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sven=20G=C3=BCnther?= Date: Wed, 29 Oct 2025 17:17:43 +0100 Subject: [PATCH] Address code review feedback Apply style improvements including type simplification, renamed flag from replaceExistingData to force, and moved CHANGELOG entry. --- CHANGELOG.md | 2 +- apps/api/src/services/interfaces/interfaces.ts | 2 +- .../services/market-data/market-data.service.ts | 16 ++++++---------- .../data-gathering/data-gathering.processor.ts | 6 +++--- .../data-gathering/data-gathering.service.ts | 8 ++++---- 5 files changed, 15 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78731b64d..b4fa29249 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,11 +15,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Improved the language localization for German (`de`) +- Ensured atomic data replacememt for historical market data fetching ### Fixed - Ensured the locale is available in the settings dialog to customize the rule thresholds of the _X-ray_ page -- Ensured atomic data replacememt for historical market data fetching ## 2.211.0 - 2025-10-25 diff --git a/apps/api/src/services/interfaces/interfaces.ts b/apps/api/src/services/interfaces/interfaces.ts index 0c7cd31c0..492c2bd35 100644 --- a/apps/api/src/services/interfaces/interfaces.ts +++ b/apps/api/src/services/interfaces/interfaces.ts @@ -20,5 +20,5 @@ export interface DataProviderResponse { export interface DataGatheringItem extends AssetProfileIdentifier { date?: Date; - replaceExistingData?: boolean; + force?: boolean; } diff --git a/apps/api/src/services/market-data/market-data.service.ts b/apps/api/src/services/market-data/market-data.service.ts index e046bc8dd..f11252984 100644 --- a/apps/api/src/services/market-data/market-data.service.ts +++ b/apps/api/src/services/market-data/market-data.service.ts @@ -206,20 +206,16 @@ export class MarketDataService { return this.prismaService.$transaction(upsertPromises); } - /** - * Atomically replace all market data for a symbol. - * Deletes existing data and inserts new data within a single transaction - * to prevent data loss if the operation fails. - */ public async replaceAllForSymbol({ dataSource, symbol, data - }: { - dataSource: DataSource; - symbol: string; - data: Prisma.MarketDataUpdateInput[]; - }): Promise { + }: AssetProfileIdentifier & { data: Prisma.MarketDataUpdateInput[] }) { + /** + * Atomically replace all market data for a symbol. + * Deletes existing data and inserts new data within a single transaction + * to prevent data loss if the operation fails. + */ await this.prismaService.$transaction(async (prisma) => { await prisma.marketData.deleteMany({ where: { diff --git a/apps/api/src/services/queues/data-gathering/data-gathering.processor.ts b/apps/api/src/services/queues/data-gathering/data-gathering.processor.ts index 57c99a87c..7863d0a50 100644 --- a/apps/api/src/services/queues/data-gathering/data-gathering.processor.ts +++ b/apps/api/src/services/queues/data-gathering/data-gathering.processor.ts @@ -100,7 +100,7 @@ export class DataGatheringProcessor { name: GATHER_HISTORICAL_MARKET_DATA_PROCESS_JOB_NAME }) public async gatherHistoricalMarketData(job: Job) { - const { dataSource, date, symbol, replaceExistingData } = job.data; + const { dataSource, date, force, symbol } = job.data; try { let currentDate = parseISO(date as unknown as string); @@ -109,7 +109,7 @@ export class DataGatheringProcessor { `Historical market data gathering has been started for ${symbol} (${dataSource}) at ${format( currentDate, DATE_FORMAT - )}${replaceExistingData ? ' (replace mode)' : ''}`, + )}${force ? ' (replace mode)' : ''}`, `DataGatheringProcessor (${GATHER_HISTORICAL_MARKET_DATA_PROCESS_JOB_NAME})` ); @@ -157,7 +157,7 @@ export class DataGatheringProcessor { currentDate = addDays(currentDate, 1); } - if (replaceExistingData) { + if (force) { await this.marketDataService.replaceAllForSymbol({ dataSource, symbol, diff --git a/apps/api/src/services/queues/data-gathering/data-gathering.service.ts b/apps/api/src/services/queues/data-gathering/data-gathering.service.ts index 7bcde097c..aff3fa4d8 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 @@ -108,7 +108,7 @@ export class DataGatheringService { await this.gatherSymbols({ dataGatheringItems, priority: DATA_GATHERING_QUEUE_PRIORITY_HIGH, - replaceExistingData: true + force: true }); } @@ -272,11 +272,11 @@ export class DataGatheringService { public async gatherSymbols({ dataGatheringItems, priority, - replaceExistingData = false + force = false }: { dataGatheringItems: DataGatheringItem[]; priority: number; - replaceExistingData?: boolean; + force?: boolean; }) { await this.addJobsToQueue( dataGatheringItems.map(({ dataSource, date, symbol }) => { @@ -285,7 +285,7 @@ export class DataGatheringService { dataSource, date, symbol, - replaceExistingData + force }, name: GATHER_HISTORICAL_MARKET_DATA_PROCESS_JOB_NAME, opts: {