Cache artists/albums for performance (fix)

This commit is contained in:
An Phan 2016-12-17 15:41:45 +08:00
parent ddabe880e5
commit ba612f5dcc
No known key found for this signature in database
GPG key ID: 05536BB4BCDC02A2
3 changed files with 8 additions and 15 deletions

View file

@ -39,6 +39,7 @@ export const albumStore = {
Vue.set(album, 'artist', artist)
Vue.set(album, 'info', null)
this.getLength(album)
this.cache[album.id] = album
return album
},
@ -62,10 +63,6 @@ export const albumStore = {
},
byId (id) {
if (!this.cache[id]) {
this.cache[id] = find(this.all, { id })
}
return this.cache[id]
},

View file

@ -24,12 +24,12 @@ export const artistStore = {
init (artists) {
this.all = artists
albumStore.init(this.all)
// Traverse through artists array to get the cover and number of songs for each.
each(this.all, artist => {
this.setupArtist(artist)
})
albumStore.init(this.all)
},
/**
@ -55,8 +55,8 @@ export const artistStore = {
}, []))
Vue.set(artist, 'songCount', artist.songs.length)
Vue.set(artist, 'info', null)
this.cache[artist.id] = artist
return artist
},
@ -85,10 +85,6 @@ export const artistStore = {
* @param {Number} id
*/
byId (id) {
if (!this.cache[id]) {
this.cache[id] = find(this.all, { id })
}
return this.cache[id]
},
@ -102,6 +98,7 @@ export const artistStore = {
each(artists, a => this.setupArtist(a))
this.all = union(this.all, artists)
},
/**

View file

@ -63,6 +63,9 @@ export const songStore = {
} else {
Vue.set(song, 'artist', artistStore.byId(song.album.artist.id))
}
// Cache the song, so that byId() is faster
this.cache[song.id] = song
},
/**
@ -131,10 +134,6 @@ export const songStore = {
* @return {Object}
*/
byId (id) {
if (!this.cache[id]) {
this.cache[id] = find(this.all, { id })
}
return this.cache[id]
},