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 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
}