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

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
+45
View File
@@ -0,0 +1,45 @@
import { rendererSend, rendererInvoke, NAMES } from '../../common/ipc'
import { throttle } from './index'
let listPosition = {}
let listPrevSelectId
const saveListPosition = throttle(() => {
rendererSend(NAMES.mainWindow.save_data, {
path: 'listPosition',
data: listPosition,
})
}, 1000)
export const initListPosition = () => {
return rendererInvoke(NAMES.mainWindow.get_data, 'listPosition').then(data => {
if (!data) data = {}
listPosition = data
})
}
export const getListPosition = id => listPosition[id] || 0
export const setListPosition = (id, position) => {
listPosition[id] = position || 0
saveListPosition()
}
export const removeListPosition = id => {
delete listPosition[id]
saveListPosition()
}
const saveListPrevSelectId = throttle(() => {
rendererSend(NAMES.mainWindow.save_data, {
path: 'listPrevSelectId',
data: listPrevSelectId,
})
}, 200)
export const initListPrevSelectId = () => {
return rendererInvoke(NAMES.mainWindow.get_data, 'listPrevSelectId').then(id => {
listPrevSelectId = id
})
}
export const getListPrevSelectId = () => listPrevSelectId
export const setListPrevSelectId = id => {
listPrevSelectId = id
saveListPrevSelectId()
}