Browse Source

Feature/switch data provider service to OnModuleInit ensuring (currency) quotes are fetched only once (#4944)

* Switch data provider service to OnModuleInit ensuring (currency) quotes are fetched only once

* Update changelog
pull/4963/head
Renegade Solutions 2 weeks ago
committed by GitHub
parent
commit
b92eff5b72
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 10
      apps/api/src/services/data-provider/data-provider.service.ts

1
CHANGELOG.md

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Adapted the options of the date range selector in the assistant dynamically based on the user’s first activity - Adapted the options of the date range selector in the assistant dynamically based on the user’s first activity
- Switched the data provider service to `OnModuleInit`, ensuring (currency) quotes are fetched only once
- Migrated the `@ghostfolio/ui/assistant` component to control flow - Migrated the `@ghostfolio/ui/assistant` component to control flow
- Migrated the `@ghostfolio/ui/value` component to control flow - Migrated the `@ghostfolio/ui/value` component to control flow
- Improved the language localization for Chinese (`zh`) - Improved the language localization for Chinese (`zh`)

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

@ -29,7 +29,7 @@ import {
import { hasRole } from '@ghostfolio/common/permissions'; import { hasRole } from '@ghostfolio/common/permissions';
import type { Granularity, UserWithSettings } from '@ghostfolio/common/types'; import type { Granularity, UserWithSettings } from '@ghostfolio/common/types';
import { Inject, Injectable, Logger } from '@nestjs/common'; import { Inject, Injectable, Logger, OnModuleInit } from '@nestjs/common';
import { DataSource, MarketData, SymbolProfile } from '@prisma/client'; import { DataSource, MarketData, SymbolProfile } from '@prisma/client';
import { Big } from 'big.js'; import { Big } from 'big.js';
import { eachDayOfInterval, format, isBefore, isValid } from 'date-fns'; import { eachDayOfInterval, format, isBefore, isValid } from 'date-fns';
@ -37,7 +37,7 @@ import { groupBy, isEmpty, isNumber, uniqWith } from 'lodash';
import ms from 'ms'; import ms from 'ms';
@Injectable() @Injectable()
export class DataProviderService { export class DataProviderService implements OnModuleInit {
private dataProviderMapping: { [dataProviderName: string]: string }; private dataProviderMapping: { [dataProviderName: string]: string };
public constructor( public constructor(
@ -48,11 +48,9 @@ export class DataProviderService {
private readonly prismaService: PrismaService, private readonly prismaService: PrismaService,
private readonly propertyService: PropertyService, private readonly propertyService: PropertyService,
private readonly redisCacheService: RedisCacheService private readonly redisCacheService: RedisCacheService
) { ) {}
this.initialize();
}
public async initialize() { public async onModuleInit() {
this.dataProviderMapping = this.dataProviderMapping =
((await this.propertyService.getByKey(PROPERTY_DATA_SOURCE_MAPPING)) as { ((await this.propertyService.getByKey(PROPERTY_DATA_SOURCE_MAPPING)) as {
[dataProviderName: string]: string; [dataProviderName: string]: string;

Loading…
Cancel
Save