Browse Source

Improve performance by caching properties in memory

pull/7484/head
Thomas Kaul 1 month ago
parent
commit
c3d2f8aa40
  1. 10
      apps/api/src/services/property/property.service.ts

10
apps/api/src/services/property/property.service.ts

@ -16,7 +16,7 @@ import { PropertyValue } from './interfaces/interfaces';
export class PropertyService { export class PropertyService {
private static readonly CACHE_TTL = ms('1 minute'); private static readonly CACHE_TTL = ms('1 minute');
private cachedProperties: Property[]; private cachedProperties: Promise<Property[]>;
private cachedPropertiesExpiresAt: Date; private cachedPropertiesExpiresAt: Date;
public constructor(private readonly prismaService: PrismaService) {} public constructor(private readonly prismaService: PrismaService) {}
@ -88,7 +88,13 @@ export class PropertyService {
return this.cachedProperties; return this.cachedProperties;
} }
this.cachedProperties = await this.prismaService.property.findMany(); this.cachedProperties = this.prismaService.property
.findMany()
.catch((error) => {
this.invalidateCache();
throw error;
});
this.cachedPropertiesExpiresAt = addMilliseconds( this.cachedPropertiesExpiresAt = addMilliseconds(
new Date(), new Date(),

Loading…
Cancel
Save