From 6db881b08f49aa323b5940c1dde082b7aef974c6 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Tue, 10 Sep 2024 14:39:52 +0200 Subject: [PATCH] Feature/optimize admin control panel endpoint using promise.all (#3741) * Optimize by using Promise.all() * Update changelog --- CHANGELOG.md | 1 + apps/api/src/app/admin/admin.service.ts | 62 ++++++++++++++----------- 2 files changed, 36 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index afc0dcc58..e4d92ad12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Optimized the asynchronous operations using `Promise.all()` in the info service +- Optimized the asynchronous operations using `Promise.all()` in the admin control panel endpoint - Extracted the users from the admin control panel endpoint to a dedicated endpoint - Improved the language localization for Italian (`it`) diff --git a/apps/api/src/app/admin/admin.service.ts b/apps/api/src/app/admin/admin.service.ts index 3f5274285..143d5c1ca 100644 --- a/apps/api/src/app/admin/admin.service.ts +++ b/apps/api/src/app/admin/admin.service.ts @@ -108,34 +108,42 @@ export class AdminService { } public async get(): Promise { - return { - exchangeRates: this.exchangeRateDataService - .getCurrencies() - .filter((currency) => { - return currency !== DEFAULT_CURRENCY; - }) - .map((currency) => { - const label1 = DEFAULT_CURRENCY; - const label2 = currency; + const exchangeRates = this.exchangeRateDataService + .getCurrencies() + .filter((currency) => { + return currency !== DEFAULT_CURRENCY; + }) + .map((currency) => { + const label1 = DEFAULT_CURRENCY; + const label2 = currency; - return { - label1, - label2, - dataSource: - DataSource[ - this.configurationService.get('DATA_SOURCE_EXCHANGE_RATES') - ], - symbol: `${label1}${label2}`, - value: this.exchangeRateDataService.toCurrency( - 1, - DEFAULT_CURRENCY, - currency - ) - }; - }), - settings: await this.propertyService.get(), - transactionCount: await this.prismaService.order.count(), - userCount: await this.prismaService.user.count(), + return { + label1, + label2, + dataSource: + DataSource[ + this.configurationService.get('DATA_SOURCE_EXCHANGE_RATES') + ], + symbol: `${label1}${label2}`, + value: this.exchangeRateDataService.toCurrency( + 1, + DEFAULT_CURRENCY, + currency + ) + }; + }); + + const [settings, transactionCount, userCount] = await Promise.all([ + this.propertyService.get(), + this.prismaService.order.count(), + this.prismaService.user.count() + ]); + + return { + exchangeRates, + settings, + transactionCount, + userCount, version: environment.version }; }