From df5e2f5f0e7041ad73f27f77c983edff61aa6d18 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Thu, 5 Sep 2024 18:23:38 +0200 Subject: [PATCH] Feature/extract common CACHE_TTL as constants (#3722) Extract CACHE_TTL * CACHE_TTL_NO_CACHE * CACHE_TTL_INFINITE --- apps/api/src/app/benchmark/benchmark.service.ts | 7 +++++-- .../src/app/portfolio/calculator/portfolio-calculator.ts | 3 ++- .../src/services/configuration/configuration.service.ts | 7 +++++-- libs/common/src/lib/config.ts | 3 +++ 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/apps/api/src/app/benchmark/benchmark.service.ts b/apps/api/src/app/benchmark/benchmark.service.ts index 6cb375e0f..f57f5fa30 100644 --- a/apps/api/src/app/benchmark/benchmark.service.ts +++ b/apps/api/src/app/benchmark/benchmark.service.ts @@ -7,7 +7,10 @@ import { MarketDataService } from '@ghostfolio/api/services/market-data/market-d import { PrismaService } from '@ghostfolio/api/services/prisma/prisma.service'; import { PropertyService } from '@ghostfolio/api/services/property/property.service'; import { SymbolProfileService } from '@ghostfolio/api/services/symbol-profile/symbol-profile.service'; -import { PROPERTY_BENCHMARKS } from '@ghostfolio/common/config'; +import { + CACHE_TTL_INFINITE, + PROPERTY_BENCHMARKS +} from '@ghostfolio/common/config'; import { DATE_FORMAT, calculateBenchmarkTrend, @@ -443,7 +446,7 @@ export class BenchmarkService { benchmarks, expiration: expiration.getTime() }), - 0 + CACHE_TTL_INFINITE ); } diff --git a/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts b/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts index 5384fd6d8..2938bd734 100644 --- a/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts +++ b/apps/api/src/app/portfolio/calculator/portfolio-calculator.ts @@ -11,6 +11,7 @@ import { ConfigurationService } from '@ghostfolio/api/services/configuration/con import { ExchangeRateDataService } from '@ghostfolio/api/services/exchange-rate-data/exchange-rate-data.service'; import { IDataGatheringItem } from '@ghostfolio/api/services/interfaces/interfaces'; import { getIntervalFromDateRange } from '@ghostfolio/common/calculation-helper'; +import { CACHE_TTL_INFINITE } from '@ghostfolio/common/config'; import { DATE_FORMAT, getSum, @@ -882,7 +883,7 @@ export abstract class PortfolioCalculator { expiration: expiration.getTime(), portfolioSnapshot: snapshot })), - 0 + CACHE_TTL_INFINITE ); return snapshot; diff --git a/apps/api/src/services/configuration/configuration.service.ts b/apps/api/src/services/configuration/configuration.service.ts index 4c5a60cce..26ef38c0a 100644 --- a/apps/api/src/services/configuration/configuration.service.ts +++ b/apps/api/src/services/configuration/configuration.service.ts @@ -1,5 +1,8 @@ import { Environment } from '@ghostfolio/api/services/interfaces/environment.interface'; -import { DEFAULT_ROOT_URL } from '@ghostfolio/common/config'; +import { + CACHE_TTL_NO_CACHE, + DEFAULT_ROOT_URL +} from '@ghostfolio/common/config'; import { Injectable } from '@nestjs/common'; import { DataSource } from '@prisma/client'; @@ -22,7 +25,7 @@ export class ConfigurationService { API_KEY_OPEN_FIGI: str({ default: '' }), API_KEY_RAPID_API: str({ default: '' }), CACHE_QUOTES_TTL: num({ default: ms('1 minute') }), - CACHE_TTL: num({ default: 1 }), + CACHE_TTL: num({ default: CACHE_TTL_NO_CACHE }), DATA_SOURCE_EXCHANGE_RATES: str({ default: DataSource.YAHOO }), DATA_SOURCE_IMPORT: str({ default: DataSource.YAHOO }), DATA_SOURCES: json({ diff --git a/libs/common/src/lib/config.ts b/libs/common/src/lib/config.ts index 50c02ae20..00e756810 100644 --- a/libs/common/src/lib/config.ts +++ b/libs/common/src/lib/config.ts @@ -30,6 +30,9 @@ export const warnColorRgb = { b: 69 }; +export const CACHE_TTL_NO_CACHE = 1; +export const CACHE_TTL_INFINITE = 0; + export const DATA_GATHERING_QUEUE = 'DATA_GATHERING_QUEUE'; export const DATA_GATHERING_QUEUE_PRIORITY_HIGH = 1; export const DATA_GATHERING_QUEUE_PRIORITY_LOW = Number.MAX_SAFE_INTEGER;