From 76d053fc85b18d293944a8e1fae3e446c2d352aa Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Sat, 2 Aug 2025 17:38:53 +0200 Subject: [PATCH] Feature/optimize performance of sitemap service (#5309) * Optimize performance * Update changelog --- CHANGELOG.md | 1 + .../app/endpoints/sitemap/sitemap.service.ts | 52 +++++++++++++------ .../middlewares/html-template.middleware.ts | 10 ++-- 3 files changed, 40 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad73d85d1..f57367bdf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- Enhanced the performance of the dynamically composed sitemap - Improved the language localization for Polish (`pl`) - Improved the language localization for Spanish (`es`) diff --git a/apps/api/src/app/endpoints/sitemap/sitemap.service.ts b/apps/api/src/app/endpoints/sitemap/sitemap.service.ts index d18fe884a..3774d2274 100644 --- a/apps/api/src/app/endpoints/sitemap/sitemap.service.ts +++ b/apps/api/src/app/endpoints/sitemap/sitemap.service.ts @@ -21,18 +21,42 @@ export class SitemapService { const rootUrl = this.configurationService.get('ROOT_URL'); return SUPPORTED_LANGUAGE_CODES.flatMap((languageCode) => { + const resourcesPath = this.i18nService.getTranslation({ + languageCode, + id: publicRoutes.resources.path.match( + SitemapService.TRANSLATION_TAGGED_MESSAGE_REGEX + ).groups.id + }); + + const personalFinanceToolsPath = this.i18nService.getTranslation({ + languageCode, + id: publicRoutes.resources.subRoutes.personalFinanceTools.path.match( + SitemapService.TRANSLATION_TAGGED_MESSAGE_REGEX + ).groups.id + }); + + const productPath = this.i18nService.getTranslation({ + languageCode, + id: publicRoutes.resources.subRoutes.personalFinanceTools.subRoutes.product.path.match( + SitemapService.TRANSLATION_TAGGED_MESSAGE_REGEX + ).groups.id + }); + return personalFinanceTools.map(({ alias, key }) => { - const route = - publicRoutes.resources.subRoutes.personalFinanceTools.subRoutes - .product; - const params = { - currentDate, - languageCode, + const location = [ rootUrl, - urlPostfix: alias ?? key - }; - - return this.createRouteSitemapUrl({ ...params, route }); + languageCode, + resourcesPath, + personalFinanceToolsPath, + `${productPath}-${alias ?? key}` + ].join('/'); + + return [ + ' ', + ` ${location}`, + ` ${currentDate}T00:00:00+00:00`, + ' ' + ].join('\n'); }); }).join('\n'); } @@ -58,14 +82,12 @@ export class SitemapService { currentDate, languageCode, rootUrl, - route, - urlPostfix + route }: { currentDate: string; languageCode: string; rootUrl: string; route?: PublicRoute; - urlPostfix?: string; }): string { const segments = route?.routerLink.map((link) => { @@ -83,9 +105,7 @@ export class SitemapService { return segment.replace(/^\/+|\/+$/, ''); }) ?? []; - const location = - [rootUrl, languageCode, ...segments].join('/') + - (urlPostfix ? `-${urlPostfix}` : ''); + const location = [rootUrl, languageCode, ...segments].join('/'); return [ ' ', diff --git a/apps/api/src/middlewares/html-template.middleware.ts b/apps/api/src/middlewares/html-template.middleware.ts index 5cf353e9a..75ec37480 100644 --- a/apps/api/src/middlewares/html-template.middleware.ts +++ b/apps/api/src/middlewares/html-template.middleware.ts @@ -154,13 +154,9 @@ export class HtmlTemplateMiddleware implements NestMiddleware { if (filename === '/assets/LICENSE') { return true; } else if ( - filename.includes('auth/ey') || - filename.includes( - 'personal-finance-tools/open-source-alternative-to-de.fi' - ) || - filename.includes( - 'personal-finance-tools/open-source-alternative-to-markets.sh' - ) + filename.endsWith('-de.fi') || + filename.endsWith('-markets.sh') || + filename.includes('auth/ey') ) { return false; }