chore: skip write to storage if diff is empty

This commit is contained in:
Cory Dransfeldt 2023-07-20 07:47:32 -07:00
parent 0059c7c97e
commit 282d3bfab5
No known key found for this signature in database

View file

@ -193,9 +193,10 @@ module.exports = async function () {
) )
const cachedTracksData = getReadableData(cachedTracksOutput.Body) const cachedTracksData = getReadableData(cachedTracksOutput.Body)
const cachedTracks = await cachedTracksData.then((tracks) => JSON.parse(tracks)).catch() const cachedTracks = await cachedTracksData.then((tracks) => JSON.parse(tracks)).catch()
const diffedTracks = diffTracks(cachedTracks, formatTracks(res, time))
const updatedCache = { const updatedCache = {
...cachedTracks, ...cachedTracks,
...diffTracks(cachedTracks, formatTracks(res, time)), ...diffedTracks,
} }
charts = deriveCharts(updatedCache) charts = deriveCharts(updatedCache)
charts.artists = Object.values(charts.artists) charts.artists = Object.values(charts.artists)
@ -205,14 +206,16 @@ module.exports = async function () {
.sort((a, b) => b.plays - a.plays) .sort((a, b) => b.plays - a.plays)
.splice(0, 8) .splice(0, 8)
await client.send( if (!_.isEmpty(diffedTracks)) {
new PutObjectCommand({ await client.send(
Bucket: WASABI_BUCKET, new PutObjectCommand({
Key: 'music.json', Bucket: WASABI_BUCKET,
Body: JSON.stringify(updatedCache), Key: 'music.json',
}) Body: JSON.stringify(updatedCache),
) })
await asset.save(charts, 'json') )
}
await asset.save(charts, 'json')
return charts return charts
} }