Browse Source

Feature/optimize performance of sitemap service (#5309)

* Optimize performance

* Update changelog
pull/5312/head
Thomas Kaul 1 week ago
committed by GitHub
parent
commit
76d053fc85
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 50
      apps/api/src/app/endpoints/sitemap/sitemap.service.ts
  3. 10
      apps/api/src/middlewares/html-template.middleware.ts

1
CHANGELOG.md

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Enhanced the performance of the dynamically composed sitemap
- Improved the language localization for Polish (`pl`) - Improved the language localization for Polish (`pl`)
- Improved the language localization for Spanish (`es`) - Improved the language localization for Spanish (`es`)

50
apps/api/src/app/endpoints/sitemap/sitemap.service.ts

@ -21,18 +21,42 @@ export class SitemapService {
const rootUrl = this.configurationService.get('ROOT_URL'); const rootUrl = this.configurationService.get('ROOT_URL');
return SUPPORTED_LANGUAGE_CODES.flatMap((languageCode) => { return SUPPORTED_LANGUAGE_CODES.flatMap((languageCode) => {
return personalFinanceTools.map(({ alias, key }) => { const resourcesPath = this.i18nService.getTranslation({
const route = languageCode,
publicRoutes.resources.subRoutes.personalFinanceTools.subRoutes id: publicRoutes.resources.path.match(
.product; SitemapService.TRANSLATION_TAGGED_MESSAGE_REGEX
const params = { ).groups.id
currentDate, });
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, languageCode,
id: publicRoutes.resources.subRoutes.personalFinanceTools.subRoutes.product.path.match(
SitemapService.TRANSLATION_TAGGED_MESSAGE_REGEX
).groups.id
});
return personalFinanceTools.map(({ alias, key }) => {
const location = [
rootUrl, rootUrl,
urlPostfix: alias ?? key languageCode,
}; resourcesPath,
personalFinanceToolsPath,
`${productPath}-${alias ?? key}`
].join('/');
return this.createRouteSitemapUrl({ ...params, route }); return [
' <url>',
` <loc>${location}</loc>`,
` <lastmod>${currentDate}T00:00:00+00:00</lastmod>`,
' </url>'
].join('\n');
}); });
}).join('\n'); }).join('\n');
} }
@ -58,14 +82,12 @@ export class SitemapService {
currentDate, currentDate,
languageCode, languageCode,
rootUrl, rootUrl,
route, route
urlPostfix
}: { }: {
currentDate: string; currentDate: string;
languageCode: string; languageCode: string;
rootUrl: string; rootUrl: string;
route?: PublicRoute; route?: PublicRoute;
urlPostfix?: string;
}): string { }): string {
const segments = const segments =
route?.routerLink.map((link) => { route?.routerLink.map((link) => {
@ -83,9 +105,7 @@ export class SitemapService {
return segment.replace(/^\/+|\/+$/, ''); return segment.replace(/^\/+|\/+$/, '');
}) ?? []; }) ?? [];
const location = const location = [rootUrl, languageCode, ...segments].join('/');
[rootUrl, languageCode, ...segments].join('/') +
(urlPostfix ? `-${urlPostfix}` : '');
return [ return [
' <url>', ' <url>',

10
apps/api/src/middlewares/html-template.middleware.ts

@ -154,13 +154,9 @@ export class HtmlTemplateMiddleware implements NestMiddleware {
if (filename === '/assets/LICENSE') { if (filename === '/assets/LICENSE') {
return true; return true;
} else if ( } else if (
filename.includes('auth/ey') || filename.endsWith('-de.fi') ||
filename.includes( filename.endsWith('-markets.sh') ||
'personal-finance-tools/open-source-alternative-to-de.fi' filename.includes('auth/ey')
) ||
filename.includes(
'personal-finance-tools/open-source-alternative-to-markets.sh'
)
) { ) {
return false; return false;
} }

Loading…
Cancel
Save