mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-15 17:30:27 +08:00
perf: 在收到对应识别结果时再重置库存数据
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1788,14 +1788,15 @@ public class AsstProxy
|
||||
}
|
||||
|
||||
var subTaskDetails = details["details"];
|
||||
AsstTaskId taskId = details["taskid"]?.ToObject<AsstTaskId>() ?? 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -515,6 +515,15 @@ public class ToolboxViewModel : Screen
|
||||
private bool _depotCacheInvalid = true;
|
||||
private string? _cachedArkPlannerResult;
|
||||
private string? _cachedLoliconResult;
|
||||
private readonly HashSet<int> _pendingDepotSyncTimeResetTaskIds = [];
|
||||
|
||||
public void MarkDepotRecognitionSyncTimeForReset(int taskId)
|
||||
{
|
||||
if (taskId > 0)
|
||||
{
|
||||
_pendingDepotSyncTimeResetTaskIds.Add(taskId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 标记仓库缓存失效
|
||||
@@ -668,14 +677,20 @@ public class ToolboxViewModel : Screen
|
||||
/// </summary>
|
||||
/// <param name="details">详细的 JSON 参数</param>
|
||||
/// <param name="updateSyncTime">是否更新同步时间为当前时间(从 Core 获取新数据时为 true,从本地加载时为 false)</param>
|
||||
/// <param name="taskId">传入对应的任务 ID 以便在收到回调后重置识别状态</param>
|
||||
/// <returns>是否成功</returns>
|
||||
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<string, int> 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<string> ExcludedItemIds =
|
||||
@@ -928,7 +945,8 @@ public class ToolboxViewModel : Screen
|
||||
/// </summary>
|
||||
public void ResetDepotRecognitionState()
|
||||
{
|
||||
DepotClear();
|
||||
// DepotParse 方法已经处理了数据清除和缓存失效,这里不需要重复调用
|
||||
// DepotClear();
|
||||
LastDepotSyncTime = null;
|
||||
}
|
||||
|
||||
@@ -1249,14 +1267,45 @@ public class ToolboxViewModel : Screen
|
||||
/// 每次传进来的都是完整数据, 临时缓存去重
|
||||
/// </summary>
|
||||
private HashSet<string> _tempOperHaveSet = [];
|
||||
private readonly HashSet<int> _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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析干员识别结果
|
||||
/// </summary>
|
||||
/// <param name="details">新增的干员数据</param>
|
||||
/// <param name="updateSyncTime">是否更新同步时间(从 Core 获取新数据时为 true,从本地加载时为 false)</param>
|
||||
/// <param name="taskId">传入对应的任务 ID 以便在收到回调后重置识别状态</param>
|
||||
/// <returns>是否成功</returns>
|
||||
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<List<OperBoxData.OperData>>()?.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
|
||||
/// </summary>
|
||||
public void ResetOperBoxRecognitionState()
|
||||
{
|
||||
OperBoxSelectedIndex = 1;
|
||||
_operBoxPotential = null;
|
||||
_tempOperHaveSet = [];
|
||||
OperBoxHaveList = [];
|
||||
OperBoxNotHaveList = [];
|
||||
ClearOperBoxRecognitionData();
|
||||
LastOperBoxSyncTime = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user