mirror of
https://github.com/koel/koel
synced 2024-11-24 21:23:06 +00:00
Cache artists/albums for performance
This commit is contained in:
parent
1ba00a0475
commit
ddabe880e5
3 changed files with 16 additions and 5 deletions
|
@ -7,6 +7,7 @@ import { songStore, artistStore } from '.'
|
|||
|
||||
export const albumStore = {
|
||||
stub,
|
||||
cache: [],
|
||||
|
||||
state: {
|
||||
albums: [stub]
|
||||
|
@ -61,7 +62,11 @@ export const albumStore = {
|
|||
},
|
||||
|
||||
byId (id) {
|
||||
return find(this.all, { id })
|
||||
if (!this.cache[id]) {
|
||||
this.cache[id] = find(this.all, { id })
|
||||
}
|
||||
|
||||
return this.cache[id]
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -10,6 +10,7 @@ const VARIOUS_ARTISTS_ID = 2
|
|||
|
||||
export const artistStore = {
|
||||
stub,
|
||||
cache: [],
|
||||
|
||||
state: {
|
||||
artists: []
|
||||
|
@ -84,7 +85,11 @@ export const artistStore = {
|
|||
* @param {Number} id
|
||||
*/
|
||||
byId (id) {
|
||||
return find(this.all, { id })
|
||||
if (!this.cache[id]) {
|
||||
this.cache[id] = find(this.all, { id })
|
||||
}
|
||||
|
||||
return this.cache[id]
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -63,9 +63,6 @@ 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
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -134,6 +131,10 @@ 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