From 868771e00eef141515f4eba9b8aac63921f83ea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= Date: Thu, 7 Nov 2024 12:07:22 +0100 Subject: [PATCH] Fix plotting of measurements with long comments Long comments were clogging up the JSON cache (Firestore has a limit of 1 MB per document). Cropping the comments down to 500 characters should push this problem many years into the future. --- CHANGELOG.md | 4 ++++ functions/kpi/progress/handleKpiProgress.js | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f30a64ee4..e3ccff733 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ All notable changes to this project will be documented in this file. The format - Dropped support for Node.js 18 and below. +### Fixed + +- Fixed plotting of measurements with very long comments. + ### Security - Updated dependencies. diff --git a/functions/kpi/progress/handleKpiProgress.js b/functions/kpi/progress/handleKpiProgress.js index d06ff28b2..df65900a9 100644 --- a/functions/kpi/progress/handleKpiProgress.js +++ b/functions/kpi/progress/handleKpiProgress.js @@ -30,7 +30,11 @@ export default async function updateKpiProgress(change, { params }) { progressCollection.map((p) => [ p.timestamp.toDate().toISOString().slice(0, 10), parseFloat(p.value.toFixed(4)), - p.comment || '', + /* + * Crop the comment to avoid bloating the cache as Firestore has a limit + * of 1 MB per document. + */ + p.comment ? p.comment.substring(0, 500) : '', ]) );