From d5dcebee0c047dcfaaef0b6e3efa44264e001442 Mon Sep 17 00:00:00 2001 From: Robbe Van Petegem Date: Thu, 30 Jun 2022 19:50:56 +0200 Subject: [PATCH] Use play stats endpoint instead of doing calculation clientside (#791) --- src/components/PercentagePlayedCard.vue | 5 +- src/components/PlayCountCard.vue | 8 +-- src/components/TopAlbumsList.vue | 6 +- src/components/TopArtistsList.vue | 12 ++-- src/components/TopTracksList.vue | 18 +++--- src/reducers.js | 76 ++++++------------------- src/views/Stats.vue | 42 +++++++++++--- 7 files changed, 75 insertions(+), 92 deletions(-) diff --git a/src/components/PercentagePlayedCard.vue b/src/components/PercentagePlayedCard.vue index 8b51de0c..41303f31 100644 --- a/src/components/PercentagePlayedCard.vue +++ b/src/components/PercentagePlayedCard.vue @@ -39,7 +39,7 @@ import { gsap } from "gsap"; export default { name: "PercentagePlayedCard", props: { - plays: { + playStats: { type: Array, required: true, }, @@ -63,8 +63,7 @@ export default { }, computed: { playedTracksInPeriod() { - const trackIds = this.plays.map((p) => p.track_id); - return [...new Set(trackIds)]; + return this.playStats.map((p) => p.track_id); }, playedTracksLength() { return this.playedTracksInPeriod.reduce((acc, cur) => { diff --git a/src/components/PlayCountCard.vue b/src/components/PlayCountCard.vue index 169163d2..ebf49f82 100644 --- a/src/components/PlayCountCard.vue +++ b/src/components/PlayCountCard.vue @@ -70,7 +70,7 @@ import { gsap } from "gsap"; export default { name: "PlayCountCard", props: { - plays: { + playStats: { type: Array, required: true, }, @@ -92,12 +92,10 @@ export default { computed: { ...mapState("tracks", ["tracks"]), playCount() { - return this.plays.length; + return this.playStats.reduce((acc, cur) => acc + cur.count, 0); }, playTime() { - return this.plays.reduce((acc, cur) => { - return acc + (this.tracks[cur.track_id]?.length || 0); - }, 0); + return this.playStats.reduce((acc, cur) => acc + cur.total_length, 0); }, }, watch: { diff --git a/src/components/TopAlbumsList.vue b/src/components/TopAlbumsList.vue index 5c61d5a4..9ca9a074 100644 --- a/src/components/TopAlbumsList.vue +++ b/src/components/TopAlbumsList.vue @@ -27,7 +27,7 @@ import TopList from "@/components/TopList"; export default { name: "TopAlbumsList", props: { - plays: { + playStats: { type: Array, required: true, }, @@ -54,8 +54,8 @@ export default { topAlbums() { return Object.entries( this.useTrackLength - ? calcPlayTimeForAlbums(this.plays, this.tracks, this.useAverage) - : calcPlayCountForAlbums(this.plays, this.tracks, this.useAverage) + ? calcPlayTimeForAlbums(this.playStats, this.tracks, this.useAverage) + : calcPlayCountForAlbums(this.playStats, this.tracks, this.useAverage) ) .sort((a1, a2) => a2[1] - a1[1]) .slice(0, 10); diff --git a/src/components/TopArtistsList.vue b/src/components/TopArtistsList.vue index 7c5dd6b1..75e279d5 100644 --- a/src/components/TopArtistsList.vue +++ b/src/components/TopArtistsList.vue @@ -7,13 +7,13 @@