Skip to content

Commit

Permalink
Merge pull request #655 from kabalin/cluster
Browse files Browse the repository at this point in the history
Use null coalescing for undefined check.
  • Loading branch information
kabalin authored Dec 28, 2023
2 parents 8099ab9 + 988f79d commit bdb285c
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions controllers/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit bdb285c

Please sign in to comment.