chore: more sorting

This commit is contained in:
Cory Dransfeldt 2023-07-20 04:31:28 -07:00
parent 6b26ae99b1
commit 0059c7c97e
No known key found for this signature in database

View file

@ -30,10 +30,8 @@ const titleCase = (string) => {
.join(' ') .join(' ')
} }
const sortByPlays = (array) => Object.values(array).sort((a, b) => b.plays - a.plays)
const diffTracks = (cache, tracks) => { const diffTracks = (cache, tracks) => {
const trackCompareSet = Object.values(tracks) const trackCompareSet = Object.values(tracks).sort((a, b) => a.time - b.time)
const cacheCompareSet = Object.values(cache).sort((a, b) => a.time - b.time) const cacheCompareSet = Object.values(cache).sort((a, b) => a.time - b.time)
const diffedTracks = {} const diffedTracks = {}
@ -200,8 +198,12 @@ module.exports = async function () {
...diffTracks(cachedTracks, formatTracks(res, time)), ...diffTracks(cachedTracks, formatTracks(res, time)),
} }
charts = deriveCharts(updatedCache) charts = deriveCharts(updatedCache)
charts.artists = sortByPlays(charts.artists).splice(0, 8) charts.artists = Object.values(charts.artists)
charts.albums = sortByPlays(charts.albums).splice(0, 8) .sort((a, b) => b.plays - a.plays)
.splice(0, 8)
charts.albums = Object.values(charts.albums)
.sort((a, b) => b.plays - a.plays)
.splice(0, 8)
await client.send( await client.send(
new PutObjectCommand({ new PutObjectCommand({