From 282d3bfab513bebe9a5e5a4339a004ebe3351a72 Mon Sep 17 00:00:00 2001 From: Cory Dransfeldt Date: Thu, 20 Jul 2023 07:47:32 -0700 Subject: [PATCH] chore: skip write to storage if diff is empty --- src/_data/music.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/_data/music.js b/src/_data/music.js index e5b3f6ff..46aac5ac 100644 --- a/src/_data/music.js +++ b/src/_data/music.js @@ -193,9 +193,10 @@ module.exports = async function () { ) const cachedTracksData = getReadableData(cachedTracksOutput.Body) const cachedTracks = await cachedTracksData.then((tracks) => JSON.parse(tracks)).catch() + const diffedTracks = diffTracks(cachedTracks, formatTracks(res, time)) const updatedCache = { ...cachedTracks, - ...diffTracks(cachedTracks, formatTracks(res, time)), + ...diffedTracks, } charts = deriveCharts(updatedCache) charts.artists = Object.values(charts.artists) @@ -205,14 +206,16 @@ module.exports = async function () { .sort((a, b) => b.plays - a.plays) .splice(0, 8) - await client.send( - new PutObjectCommand({ - Bucket: WASABI_BUCKET, - Key: 'music.json', - Body: JSON.stringify(updatedCache), - }) - ) - await asset.save(charts, 'json') + if (!_.isEmpty(diffedTracks)) { + await client.send( + new PutObjectCommand({ + Bucket: WASABI_BUCKET, + Key: 'music.json', + Body: JSON.stringify(updatedCache), + }) + ) + } + await asset.save(charts, 'json') return charts }