From 1b68e6d22f56309bce4b2cb08fdc73abe65b8c5b Mon Sep 17 00:00:00 2001 From: uye <99072975+ABA2396@users.noreply.github.com> Date: Fri, 27 Mar 2026 06:29:27 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=9C=A8=E6=94=B6=E5=88=B0=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=E8=AF=86=E5=88=AB=E7=BB=93=E6=9E=9C=E6=97=B6=E5=86=8D?= =?UTF-8?q?=E9=87=8D=E7=BD=AE=E5=BA=93=E5=AD=98=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + src/MaaWpfGui/Main/AsstProxy.cs | 5 +- .../ViewModels/UI/ToolboxViewModel.cs | 65 ++++++++++++++++--- .../UserDataUpdateSettingsUserControlModel.cs | 12 ++-- 4 files changed, 67 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index becffabc81..2324d67cae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ Besides DeepSleep, this update also fixes several small but noticeable issues. ### 改进 | Improved +* 在收到对应识别结果时再重置库存数据 @ABA2396 * 使用 DateTimeOffset 替代 DateTime @status102 * Log 头时间从 UTC 时间改为 Local 时间 @status102 * 不再默认启用 `在下拉框中隐藏当日未开放关卡` @status102 diff --git a/src/MaaWpfGui/Main/AsstProxy.cs b/src/MaaWpfGui/Main/AsstProxy.cs index 8e28e4bfaa..12c3deaff1 100644 --- a/src/MaaWpfGui/Main/AsstProxy.cs +++ b/src/MaaWpfGui/Main/AsstProxy.cs @@ -1788,14 +1788,15 @@ public class AsstProxy } var subTaskDetails = details["details"]; + AsstTaskId taskId = details["taskid"]?.ToObject() ?? 0; switch (taskChain) { case "Depot": - Instances.ToolboxViewModel.DepotParse((JObject?)subTaskDetails, updateSyncTime: true); + Instances.ToolboxViewModel.DepotParse((JObject?)subTaskDetails, updateSyncTime: true, taskId); break; case "OperBox": - Instances.ToolboxViewModel.OperBoxParse((JObject?)subTaskDetails, updateSyncTime: true); + Instances.ToolboxViewModel.OperBoxParse((JObject?)subTaskDetails, updateSyncTime: true, taskId); break; } diff --git a/src/MaaWpfGui/ViewModels/UI/ToolboxViewModel.cs b/src/MaaWpfGui/ViewModels/UI/ToolboxViewModel.cs index c1e19dd71e..d73ea78d88 100644 --- a/src/MaaWpfGui/ViewModels/UI/ToolboxViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/ToolboxViewModel.cs @@ -515,6 +515,15 @@ public class ToolboxViewModel : Screen private bool _depotCacheInvalid = true; private string? _cachedArkPlannerResult; private string? _cachedLoliconResult; + private readonly HashSet _pendingDepotSyncTimeResetTaskIds = []; + + public void MarkDepotRecognitionSyncTimeForReset(int taskId) + { + if (taskId > 0) + { + _pendingDepotSyncTimeResetTaskIds.Add(taskId); + } + } /// /// 标记仓库缓存失效 @@ -668,14 +677,20 @@ public class ToolboxViewModel : Screen /// /// 详细的 JSON 参数 /// 是否更新同步时间为当前时间(从 Core 获取新数据时为 true,从本地加载时为 false) + /// 传入对应的任务 ID 以便在收到回调后重置识别状态 /// 是否成功 - public bool DepotParse(JObject? details, bool updateSyncTime = false) + public bool DepotParse(JObject? details, bool updateSyncTime = false, int taskId = 0) { if (details == null) { return false; } + if (_pendingDepotSyncTimeResetTaskIds.Remove(taskId)) + { + ResetDepotRecognitionState(); + } + DepotResult.Clear(); Dictionary depotItems = []; @@ -758,7 +773,7 @@ public class ToolboxViewModel : Screen if (updateSyncTime) { // 从 Core 获取新数据,更新为当前 UTC 时间 - AchievementTrackerHelper.Instance.CheckResyncAfterDays(LastDepotSyncTime, 7, AchievementIds.ResumeRecord); + AchievementTrackerHelper.Instance.CheckResyncAfterDays(LastDepotSyncTime?.UtcDateTime, 7, AchievementIds.ResumeRecord); LastDepotSyncTime = DateTimeOffset.UtcNow; } else @@ -804,11 +819,13 @@ public class ToolboxViewModel : Screen DepotInfo = LocalizationHelper.GetString("CopiedToClipboard"); } + /* private void DepotClear() { DepotResult.Clear(); InvalidateDepotCache(); } + */ // 需要排除的物品 ID(不统计到仓库) private static readonly HashSet ExcludedItemIds = @@ -928,7 +945,8 @@ public class ToolboxViewModel : Screen /// public void ResetDepotRecognitionState() { - DepotClear(); + // DepotParse 方法已经处理了数据清除和缓存失效,这里不需要重复调用 + // DepotClear(); LastDepotSyncTime = null; } @@ -1249,14 +1267,45 @@ public class ToolboxViewModel : Screen /// 每次传进来的都是完整数据, 临时缓存去重 /// private HashSet _tempOperHaveSet = []; + private readonly HashSet _pendingOperBoxRecognitionResetTaskIds = []; - public bool OperBoxParse(JObject? details, bool updateSyncTime = true) + public void MarkOperBoxRecognitionDataForReset(int taskId) + { + if (taskId > 0) + { + _pendingOperBoxRecognitionResetTaskIds.Add(taskId); + } + } + + private void ClearOperBoxRecognitionData() + { + OperBoxSelectedIndex = 1; + _operBoxPotential = null; + _tempOperHaveSet = []; + OperBoxHaveList = []; + OperBoxNotHaveList = []; + LastOperBoxSyncTime = null; + } + + /// + /// 解析干员识别结果 + /// + /// 新增的干员数据 + /// 是否更新同步时间(从 Core 获取新数据时为 true,从本地加载时为 false) + /// 传入对应的任务 ID 以便在收到回调后重置识别状态 + /// 是否成功 + public bool OperBoxParse(JObject? details, bool updateSyncTime = true, int taskId = 0) { if (details == null) { return false; } + if (_pendingOperBoxRecognitionResetTaskIds.Remove(taskId)) + { + ResetOperBoxRecognitionState(); + } + var ownOpers = (details["own_opers"] as JArray)?.ToObject>()?.Where(o => !string.IsNullOrEmpty(o.Id)).ToList(); if (ownOpers is null) { @@ -1300,7 +1349,7 @@ public class ToolboxViewModel : Screen if (updateSyncTime) { - AchievementTrackerHelper.Instance.CheckResyncAfterDays(LastOperBoxSyncTime, 7, AchievementIds.ResumeRecord); + AchievementTrackerHelper.Instance.CheckResyncAfterDays(LastOperBoxSyncTime?.UtcDateTime, 7, AchievementIds.ResumeRecord); LastOperBoxSyncTime = DateTimeOffset.UtcNow; } else @@ -1324,11 +1373,7 @@ public class ToolboxViewModel : Screen /// public void ResetOperBoxRecognitionState() { - OperBoxSelectedIndex = 1; - _operBoxPotential = null; - _tempOperHaveSet = []; - OperBoxHaveList = []; - OperBoxNotHaveList = []; + ClearOperBoxRecognitionData(); LastOperBoxSyncTime = null; } diff --git a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/UserDataUpdateSettingsUserControlModel.cs b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/UserDataUpdateSettingsUserControlModel.cs index 9e6e4cf1f0..d847cc410c 100644 --- a/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/UserDataUpdateSettingsUserControlModel.cs +++ b/src/MaaWpfGui/ViewModels/UserControl/TaskQueue/UserDataUpdateSettingsUserControlModel.cs @@ -103,24 +103,28 @@ public class UserDataUpdateSettingsUserControlModel : TaskSettingsViewModel, Use bool ret = false; if (operBoxTriggerDue) { - Execute.OnUIThread(Instances.ToolboxViewModel.ResetOperBoxRecognitionState); ret = Instances.ToolboxViewModel.StartOperBoxRecognitionTask(startImmediately: false); if (!ret) { return (false, []); } - ids.Add(Instances.AsstProxy.TasksStatus.Last().Key); + + int operBoxTaskId = Instances.AsstProxy.TasksStatus.Last().Key; + Instances.ToolboxViewModel.MarkOperBoxRecognitionDataForReset(operBoxTaskId); + ids.Add(operBoxTaskId); } if (depotTriggerDue) { - Execute.OnUIThread(Instances.ToolboxViewModel.ResetDepotRecognitionState); ret = Instances.ToolboxViewModel.StartDepotRecognitionTask(false); if (!ret) { return (false, []); } - ids.Add(Instances.AsstProxy.TasksStatus.Last().Key); + + int depotTaskId = Instances.AsstProxy.TasksStatus.Last().Key; + Instances.ToolboxViewModel.MarkDepotRecognitionSyncTimeForReset(depotTaskId); + ids.Add(depotTaskId); } if (ret && operBoxTriggerDue && depotTriggerDue)