From 0ff05d960f4258b53b73c2e973f152043eba3a29 Mon Sep 17 00:00:00 2001 From: yan Date: Sun, 11 Jan 2026 11:05:53 +0800 Subject: [PATCH] =?UTF-8?q?refactor(FullyAutoAndSemiAutoTools):=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=BF=90=E8=A1=8C=E9=98=9F=E5=88=97=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E6=8F=90=E9=AB=98=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 使用 Set 替代数组查找操作提升性能 - 实现批量删除机制避免迭代过程中的元素删除问题 - 重构代码结构优先处理上次群组未执行的任务 - 添加 lastRunMap 存储并处理剩余任务 - 优化迭代逻辑确保任务按预期顺序执行 --- repo/js/FullyAutoAndSemiAutoTools/main.js | 26 ++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/repo/js/FullyAutoAndSemiAutoTools/main.js b/repo/js/FullyAutoAndSemiAutoTools/main.js index 13a74c8fc..6ff38f868 100644 --- a/repo/js/FullyAutoAndSemiAutoTools/main.js +++ b/repo/js/FullyAutoAndSemiAutoTools/main.js @@ -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);