mirror of
https://github.com/koel/koel
synced 2024-11-10 14:44:13 +00:00
Cache artists/albums for performance (fix)
This commit is contained in:
parent
ddabe880e5
commit
ba612f5dcc
3 changed files with 8 additions and 15 deletions
|
@ -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]
|
||||
},
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -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]
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue