优化我的列表、下载、歌单、排行榜列表性能

This commit is contained in:
lyswhut
2021-10-26 14:44:15 +08:00
parent 0d20869337
commit 35ca6db1ee
18 changed files with 646 additions and 335 deletions
+17 -29
View File
@@ -9,9 +9,7 @@ for (const source of music.sources) {
sources.push(source)
}
// state
const state = {
boards: sourceList,
const listInfo = {
list: [],
total: 0,
page: 1,
@@ -19,6 +17,11 @@ const state = {
key: null,
}
// state
const state = {
boards: sourceList,
}
// getters
const getters = {
sources(state, getters, rootState, { sourceNames }) {
@@ -27,16 +30,6 @@ const getters = {
boards(state) {
return state.boards
},
list(state) {
return state.list
},
info(state) {
return {
total: state.total,
limit: state.limit,
page: state.page,
}
},
}
// actions
@@ -47,7 +40,6 @@ const actions = {
// let tabId = rootState.setting.leaderboard.tabId
// let key = `${source}${tabId}${page}`
// if (state.list.length && state.key == key) return true
// commit('clearList')
if (state.boards[source].length) return
return music[source].leaderboard.getBoards().then(result => commit('setBoardsList', { boards: result, source }))
},
@@ -56,14 +48,22 @@ const actions = {
let tabId = rootState.setting.leaderboard.tabId
let [source, bangId] = tabId.split('__')
let key = `${source}${tabId}${page}`
if (state.list.length && state.key == key) return Promise.resolve()
commit('clearList')
if (listInfo.list.length && listInfo.key == key) return Promise.resolve(listInfo)
// commit('clearList')
// return (
// cache.has(key)
// ? Promise.resolve(cache.get(key))
// : music[source].leaderboard.getList(bangId, page)
// ).then(result => commit('setList', { result, key }))
return music[source].leaderboard.getList(bangId, page).then(result => commit('setList', { result, key }))
return music[source].leaderboard.getList(bangId, page).then(result => {
cache.set(key, result)
listInfo.list = result.list
listInfo.total = result.total
listInfo.limit = result.limit
listInfo.page = result.page
listInfo.key = key
return listInfo
})
},
getListAll({ state, rootState }, id) {
// console.log(source, id)
@@ -96,18 +96,6 @@ const mutations = {
setBoardsList(state, { boards, source }) {
state.boards[source] = boards.list
},
setList(state, { result, key }) {
state.list = result.list
state.total = result.total
state.limit = result.limit
state.page = result.page
state.key = key
cache.set(key, result)
},
clearList(state) {
state.list = []
state.total = 0
},
}
export default {
+5 -3
View File
@@ -1,6 +1,7 @@
import musicSdk from '../../utils/music'
import { clearLyric, clearMusicUrl } from '../../utils'
import { sync as eventSyncName } from '@renderer/event/names'
import { removeListPosition, setListPrevSelectId } from '@renderer/utils/data'
let allList = {}
window.allList = allList
@@ -340,6 +341,7 @@ const mutations = {
if (index < 0) return
let list = state.userList.splice(index, 1)[0]
allListRemove(list)
removeListPosition(id)
},
setUserListName(state, { id, name, isSync }) {
if (!isSync) {
@@ -380,9 +382,6 @@ const mutations = {
state.userList.splice(index, 1)
state.userList.splice(index + 1, 0, targetList)
},
setListScroll(state, { id, location }) {
if (allList[id]) allList[id].location = location
},
setMusicPosition(state, { id, position, list, isSync }) {
if (!isSync) {
window.eventHub.$emit(eventSyncName.send_action_list, {
@@ -418,6 +417,9 @@ const mutations = {
setOtherSource(state, { musicInfo, otherSource }) {
musicInfo.otherSource = otherSource
},
setPrevSelectListId(state, val) {
setListPrevSelectId(val)
},
}
export default {