Browse Source

Task/enable browser cache for logo endpoints (#7956)

* Enable browser cache

* Update changelog
pull/7904/head
Thomas Kaul 24 hours ago
committed by GitHub
parent
commit
ed7138cf5f
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 15
      apps/api/src/app/logo/logo.controller.ts

1
CHANGELOG.md

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed ### Changed
- Simplified the portfolio summary by hiding the currency on mobile - Simplified the portfolio summary by hiding the currency on mobile
- Improved the performance of the logo endpoints by enabling the browser cache
- Improved the language localization for Catalan (`ca`) - Improved the language localization for Catalan (`ca`)
### Fixed ### Fixed

15
apps/api/src/app/logo/logo.controller.ts

@ -11,12 +11,15 @@ import {
} from '@nestjs/common'; } from '@nestjs/common';
import { DataSource } from '@prisma/client'; import { DataSource } from '@prisma/client';
import { Response } from 'express'; import { Response } from 'express';
import ms from 'ms';
import { GetLogoDto } from './get-logo.dto'; import { GetLogoDto } from './get-logo.dto';
import { LogoService } from './logo.service'; import { LogoService } from './logo.service';
@Controller('logo') @Controller('logo')
export class LogoController { export class LogoController {
private static readonly CACHE_MAX_AGE_IN_SECONDS = ms('7 days') / 1000;
public constructor(private readonly logoService: LogoService) {} public constructor(private readonly logoService: LogoService) {}
@Get(':dataSource/:symbol') @Get(':dataSource/:symbol')
@ -34,6 +37,12 @@ export class LogoController {
}); });
response.contentType(type); response.contentType(type);
response.setHeader(
'Cache-Control',
`public, max-age=${LogoController.CACHE_MAX_AGE_IN_SECONDS}`
);
response.send(buffer); response.send(buffer);
} catch { } catch {
response.status(HttpStatus.NOT_FOUND).send(); response.status(HttpStatus.NOT_FOUND).send();
@ -49,6 +58,12 @@ export class LogoController {
const { buffer, type } = await this.logoService.getLogoByUrl(url); const { buffer, type } = await this.logoService.getLogoByUrl(url);
response.contentType(type); response.contentType(type);
response.setHeader(
'Cache-Control',
`public, max-age=${LogoController.CACHE_MAX_AGE_IN_SECONDS}`
);
response.send(buffer); response.send(buffer);
} catch { } catch {
response.status(HttpStatus.NOT_FOUND).send(); response.status(HttpStatus.NOT_FOUND).send();

Loading…
Cancel
Save