From 988f79d7f31041f9faf7d9b4b0177f66e92d432a Mon Sep 17 00:00:00 2001 From: Ruslan Kabalin Date: Wed, 27 Dec 2023 22:48:51 +0000 Subject: [PATCH] Use null coalescing for undefined check. Also make sure y attribute is defined (if cluster was missing, it will be undefined). Fixes #653 --- controllers/cluster.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/controllers/cluster.js b/controllers/cluster.js index fe4d0641..9d994f72 100644 --- a/controllers/cluster.js +++ b/controllers/cluster.js @@ -161,7 +161,7 @@ export const clusterPhotosAll = async function (params) { } cluster.c += 1; - cluster.y[photo.year] = 1 + (cluster.y[photo.year] | 0); + cluster.y[photo.year] = 1 + (cluster.y[photo.year] ?? 0); if (useGravity) { cluster.geo[0] += geoPhoto[0]; @@ -285,10 +285,8 @@ async function clusterRecalcByPhoto(g, zParam, geoPhotos, yearPhotos, isPainting } if (yearPhotos.n) { - yCluster[String(yearPhotos.n)] = 1 + (yCluster[String(yearPhotos.n)] | 0); + yCluster[String(yearPhotos.n)] = 1 + (yCluster[String(yearPhotos.n)] ?? 0); } - - $update.$set.y = yCluster; } // Such a situation shouldn't be @@ -333,6 +331,7 @@ async function clusterRecalcByPhoto(g, zParam, geoPhotos, yearPhotos, isPainting $update.$set.p = photo; $update.$set.geo = geoCluster; + $update.$set.y = yCluster; const { n: count = 0 } = await ClusterModel.updateOne({ g, z: zParam.z }, $update, { upsert: true }).exec(); @@ -480,7 +479,7 @@ export async function getBoundsByYear({ geometry, z, year, year2, isPainting }) cluster.c = 0; for (let y = year; y <= year2; y++) { - cluster.c += cluster.y[y] | 0; + cluster.c += cluster.y[y] ?? 0; } if (cluster.c > 0) {