From 2ee0114b1492a952cf11cfed4d84fce960b9fb06 Mon Sep 17 00:00:00 2001 From: status102 <102887808+status102@users.noreply.github.com> Date: Tue, 25 Feb 2025 20:01:13 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E8=87=AA=E5=8A=A8=E6=88=98=E6=96=97?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E9=9D=9E=E5=8D=B3=E6=97=B6=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E6=97=B6=EF=BC=8C=E4=BD=BF=E7=94=A8=E5=B7=B2?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E7=9A=84=E7=BC=93=E5=AD=98=E6=9B=BF=E4=BB=A3?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewModels/UI/CopilotViewModel.cs | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/MaaWpfGui/ViewModels/UI/CopilotViewModel.cs b/src/MaaWpfGui/ViewModels/UI/CopilotViewModel.cs index 6ac26fb2ab..0a99422afd 100644 --- a/src/MaaWpfGui/ViewModels/UI/CopilotViewModel.cs +++ b/src/MaaWpfGui/ViewModels/UI/CopilotViewModel.cs @@ -54,6 +54,11 @@ namespace MaaWpfGui.ViewModels.UI private readonly List _copilotIdList = []; // 用于保存作业列表中的作业的Id,对于同一个作业,只有都执行成功才点赞 private readonly List _recentlyRatedCopilotId = []; // TODO: 可能考虑加个持久化 private AsstTaskType _taskType = AsstTaskType.Copilot; + + /// + /// 缓存的已解析作业,非即时添加的作业会使用该缓存 + /// + private CopilotBase? _copilotCache; private const string CopilotIdPrefix = "maa://"; private const string TempCopilotFile = "cache/_temp_copilot.json"; private static readonly string[] _supportExt = [".json", ".mp4", ".m4s", ".mkv", ".flv", ".avi"]; @@ -408,6 +413,7 @@ namespace MaaWpfGui.ViewModels.UI } CopilotId = 0; + _copilotCache = null; foreach (var file in dialog.FileNames) { var fileInfo = new FileInfo(file); @@ -544,6 +550,7 @@ namespace MaaWpfGui.ViewModels.UI MapUrl = MapUiUrl; IsDataFromWeb = false; CopilotId = 0; + _copilotCache = null; int copilotId = 0; bool writeToCache = false; @@ -681,6 +688,7 @@ namespace MaaWpfGui.ViewModels.UI } _taskType = AsstTaskType.Copilot; + _copilotCache = copilot; if (copilot.Documentation?.Details is not null) { CopilotUrl = CopilotUiUrl; @@ -746,6 +754,7 @@ namespace MaaWpfGui.ViewModels.UI } _taskType = AsstTaskType.SSSCopilot; + _copilotCache = copilot; MapUrl = MapUiUrl.Replace("areas", "map/" + copilot.StageName); if (copilot.Documentation?.Details is not null) { @@ -827,6 +836,7 @@ namespace MaaWpfGui.ViewModels.UI private async Task ParseCopilotSetAsync(PrtsCopilotSetModel.CopilotSetData? copilotSet) { CopilotId = 0; + _copilotCache = null; ClearLog(); if (copilotSet?.CopilotIds is null) { @@ -943,21 +953,9 @@ namespace MaaWpfGui.ViewModels.UI return; } - string file; try { - file = await File.ReadAllTextAsync(IsDataFromWeb ? TempCopilotFile : Filename); - } - catch - { - AddLog(LocalizationHelper.GetString("CopilotFileReadError"), UiLogColor.Error, showTime: false); - return; - } - - try - { - var copilot = JsonConvert.DeserializeObject(file); - if (copilot is not null) + if (_copilotCache is CopilotModel { } copilot) { await AddCopilotTaskToList(copilot, !isRaid ? CopilotModel.DifficultyFlags.Normal : CopilotModel.DifficultyFlags.Raid, stageName, CopilotId); }