From deafd7330665989fc6526d76b0bd27d8e0645abb Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Mon, 17 Feb 2025 20:00:28 +0800 Subject: [PATCH] Optimize RemoveInvalidServerResult --- v2rayN/ServiceLib/Handler/ConfigHandler.cs | 25 ++++++++----------- .../ViewModels/ProfilesViewModel.cs | 2 +- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs index 63e54694..06934b4b 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -294,7 +294,7 @@ namespace ServiceLib.Handler /// /// /// - public static async Task RemoveServer(Config config, List indexes) + public static async Task RemoveServers(Config config, List indexes) { var subid = "TempRemoveSubId"; foreach (var item in indexes) @@ -303,7 +303,7 @@ namespace ServiceLib.Handler } await SQLiteHelper.Instance.UpdateAllAsync(indexes); - await RemoveServerViaSubid(config, subid, false); + await RemoveServersViaSubid(config, subid, false); return 0; } @@ -886,7 +886,7 @@ namespace ServiceLib.Handler lstRemove.Add(item); } } - await RemoveServer(config, lstRemove); + await RemoveServers(config, lstRemove); return new Tuple(lstProfile.Count, lstKeep.Count); } @@ -1062,12 +1062,9 @@ namespace ServiceLib.Handler var lstProfile = (from t in lstModel join t2 in lstProfileExs on t.IndexId equals t2.IndexId where t2.Delay == -1 - select t.IndexId).ToList(); + select t).ToList(); - foreach (var item in lstProfile) - { - await RemoveProfileItem(config, item); - } + await RemoveServers(config, JsonUtils.Deserialize>(JsonUtils.Serialize(lstProfile))); return lstProfile.Count; } @@ -1094,7 +1091,7 @@ namespace ServiceLib.Handler //remove sub items if (isSub && Utils.IsNotEmpty(subid)) { - await RemoveServerViaSubid(config, subid, isSub); + await RemoveServersViaSubid(config, subid, isSub); subFilter = (await AppHandler.Instance.GetSubItem(subid))?.Filter ?? ""; } @@ -1188,7 +1185,7 @@ namespace ServiceLib.Handler { if (isSub && Utils.IsNotEmpty(subid)) { - await RemoveServerViaSubid(config, subid, isSub); + await RemoveServersViaSubid(config, subid, isSub); } int count = 0; foreach (var it in lstProfiles) @@ -1244,7 +1241,7 @@ namespace ServiceLib.Handler if (isSub && Utils.IsNotEmpty(subid)) { - await RemoveServerViaSubid(config, subid, isSub); + await RemoveServersViaSubid(config, subid, isSub); } profileItem.Subid = subid; @@ -1269,7 +1266,7 @@ namespace ServiceLib.Handler if (isSub && Utils.IsNotEmpty(subid)) { - await RemoveServerViaSubid(config, subid, isSub); + await RemoveServersViaSubid(config, subid, isSub); } var lstSsServer = ShadowsocksFmt.ResolveSip008(strData); @@ -1456,7 +1453,7 @@ namespace ServiceLib.Handler /// /// /// - public static async Task RemoveServerViaSubid(Config config, string subid, bool isSub) + public static async Task RemoveServersViaSubid(Config config, string subid, bool isSub) { if (Utils.IsNullOrEmpty(subid)) { @@ -1487,7 +1484,7 @@ namespace ServiceLib.Handler return 0; } await SQLiteHelper.Instance.DeleteAsync(item); - await RemoveServerViaSubid(config, id, false); + await RemoveServersViaSubid(config, id, false); return 0; } diff --git a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs index e83195d8..9405a42a 100644 --- a/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs @@ -520,7 +520,7 @@ namespace ServiceLib.ViewModels } var exists = lstSelecteds.Exists(t => t.IndexId == _config.IndexId); - await ConfigHandler.RemoveServer(_config, lstSelecteds); + await ConfigHandler.RemoveServers(_config, lstSelecteds); NoticeHandler.Instance.Enqueue(ResUI.OperationSuccess); if (lstSelecteds.Count == _profileItems.Count) {