我正在制作一个本地音乐播放器,但当从文件夹扫描的音频数量过多时,会发生以下内存方面的错误:
以下是数据库相关代码:
searchData(text = '', flag = 0, args = [], table_name = this._tableName) {
return new Promise((resolve, reject) => {
const transaction = this._db.transaction(table_name, 'readwrite'); // 启动事务,'readwrite' 表示读写操作
const store = transaction.objectStore(table_name);
let search_requests;
let pathIndex;
switch (flag) {
case 0:
search_requests = store.openCursor();
break;
case 1:
pathIndex = store.index('path')
search_requests = pathIndex.openCursor(IDBKeyRange.only(text));
break;
case 2:
break;
}
search_requests.onsuccess = event => {
const cursor = event.target.result;
if (cursor) {
args.push(cursor.value);
if (flag === 1) {
resolve(1)
}
cursor.continue()
} else {
if (flag === 1) {
resolve(0)
}
if (flag === 0) {
resolve(args)
}
}
}
search_requests.onerror = event => {
console.log('search error: ', event);
}
return [];
})
}
以下是渲染端相关代码:
watch([sort_key, isReverse], async () => {
cache_list.value.length = 0;
db.init_DB().then(() => {
db.searchData('', 0).then(data => {
data.forEach(item => {
const position = findInsertPosition(cache_list.value, item[sort_key.value], sort_key.value)
cache_list.value.splice(position, 0, item)
})
if (isReverse.value) {
cache_list.value.reverse()
}
search()
})
})
}, {immediate: true})
cache_list是虚拟列表,用来展示数据
我没有相关经验,不知道如何修改
在网上搜索过相关内容,但毫无帮助