From 1f0381228ec226f8bc91694b1a692ad2285f52e5 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Tue, 4 Oct 2022 17:39:51 +0200 Subject: [PATCH] Feature/improve caching of benchmarks (#1320) * Improve caching * Update changelog --- CHANGELOG.md | 6 ++++++ apps/api/src/app/benchmark/benchmark.service.ts | 15 ++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5c492add..8d922bd95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Changed + +- Improved the caching of the benchmarks in the markets overview (only cache if fetching was successful) + ## 1.201.0 - 01.10.2022 ### Added diff --git a/apps/api/src/app/benchmark/benchmark.service.ts b/apps/api/src/app/benchmark/benchmark.service.ts index 68968b09f..015fc7ee7 100644 --- a/apps/api/src/app/benchmark/benchmark.service.ts +++ b/apps/api/src/app/benchmark/benchmark.service.ts @@ -73,6 +73,7 @@ export class BenchmarkService { } const allTimeHighs = await Promise.all(promises); + let storeInCache = true; benchmarks = allTimeHighs.map((allTimeHigh, index) => { const { marketPrice } = @@ -85,6 +86,8 @@ export class BenchmarkService { allTimeHigh, marketPrice ); + } else { + storeInCache = false; } return { @@ -100,11 +103,13 @@ export class BenchmarkService { }; }); - await this.redisCacheService.set( - this.CACHE_KEY_BENCHMARKS, - JSON.stringify(benchmarks), - ms('4 hours') / 1000 - ); + if (storeInCache) { + await this.redisCacheService.set( + this.CACHE_KEY_BENCHMARKS, + JSON.stringify(benchmarks), + ms('4 hours') / 1000 + ); + } return benchmarks; }