mirror of
https://github.com/babalae/bettergi-scripts-list.git
synced 2026-03-28 05:29:52 +08:00
refactor(FullyAutoAndSemiAutoTools): 优化运行队列逻辑提高性能
- 使用 Set 替代数组查找操作提升性能 - 实现批量删除机制避免迭代过程中的元素删除问题 - 重构代码结构优先处理上次群组未执行的任务 - 添加 lastRunMap 存储并处理剩余任务 - 优化迭代逻辑确保任务按预期顺序执行
This commit is contained in:
@@ -744,12 +744,28 @@ async function treeToList(treeList = []) {
|
||||
})()
|
||||
|
||||
async function main() {
|
||||
// await runMap(needRunMap)
|
||||
// for (let key of needRunMap.keys()) {
|
||||
// await runList(needRunMap.get(key))
|
||||
// }
|
||||
let lastRunMap = new Map()
|
||||
if (RecordLast.groupPaths.size > 0 && RecordLast.paths.size !== RecordLast.groupPaths.size) {
|
||||
//优先跑上次群组没跑过的
|
||||
// 由于在迭代过程中删除元素会影响迭代,先收集要删除的键
|
||||
const keysToDelete = [];
|
||||
// 优先跑上次群组没跑过的
|
||||
// 使用 Set 提高性能
|
||||
const lastListSet = new Set([...RecordLast.groupPaths].map(item => item.name));
|
||||
|
||||
for (const [key, one] of needRunMap.entries()) {
|
||||
if (!lastListSet.has(key)) {
|
||||
lastRunMap.set(key, one);
|
||||
keysToDelete.push(key);
|
||||
}
|
||||
}
|
||||
// 然后批量删除
|
||||
for (const key of keysToDelete) {
|
||||
needRunMap.delete(key);
|
||||
}
|
||||
}
|
||||
await runMap(needRunMap)
|
||||
if (lastRunMap.size > 0) {
|
||||
await runMap(lastRunMap)
|
||||
}
|
||||
log.info(`[{mode}] path==>{path},请按下{key}以继续执行[${manifest.name} JS]`, settings.mode, "path", AUTO_STOP)
|
||||
await keyMousePress(AUTO_STOP);
|
||||
|
||||
Reference in New Issue
Block a user