From 8845dd26d07a171e4a5a8cbb3cf8f0c536754cbf Mon Sep 17 00:00:00 2001 From: Niklas Fondberg Date: Mon, 20 Sep 2021 16:11:00 +0200 Subject: [PATCH] Generate new interiors on focus point changes and break Cloudfront cache (#50) * gen-new-interiors-on-focus-changes * Remove 1 hour cache * Cachebreak CDN --- src/datasources/imageserver-api.ts | 2 +- src/datasources/interior-api.ts | 2 +- src/resolvers/products-resolver.ts | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/datasources/imageserver-api.ts b/src/datasources/imageserver-api.ts index b9ab7eb..cfb0c7a 100644 --- a/src/datasources/imageserver-api.ts +++ b/src/datasources/imageserver-api.ts @@ -12,7 +12,7 @@ export class ImageServerApi extends RESTDataSource { async getInteriorsForProduct( productId: number, ): Promise> { - return this.get(`/rooms/${productId}/`, null, { + return this.get(`/rooms/${productId}/?ts=${Date.now()}`, null, { cacheOptions: { ttl: 5 }, }); } diff --git a/src/datasources/interior-api.ts b/src/datasources/interior-api.ts index b82e379..7cc8c99 100644 --- a/src/datasources/interior-api.ts +++ b/src/datasources/interior-api.ts @@ -68,7 +68,7 @@ export class InteriorAPI extends BaseSQLDataSource { `; const allInteriors = await this.cachedRaw(sql) - .cache(MINUTE * 60) + .cache(60) .then((data) => data.rows.map((row) => { const res = { diff --git a/src/resolvers/products-resolver.ts b/src/resolvers/products-resolver.ts index 9e3bbb0..9cafeb1 100644 --- a/src/resolvers/products-resolver.ts +++ b/src/resolvers/products-resolver.ts @@ -101,6 +101,14 @@ export const productMutationTypeDefs = { focusXpoint2, focusYpoint2, ); + + // generate new interiors + const product = await (dataSources.productApi).getProduct( + productId, + ); + await (( + dataSources.interiorsLambdaApi + )).generateNewInteriors(product); return (dataSources.productApi).getProduct(productId); }, async productBlacklisting(_, { productId, markets }, { dataSources }) {