From 9fd20ff0010bdeadd77a3c8ff9fe9f45fed9b055 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Mon, 28 Oct 2024 09:38:20 +0800 Subject: [PATCH] De-duplication after subscription update --- v2rayN/ServiceLib/Services/UpdateService.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/v2rayN/ServiceLib/Services/UpdateService.cs b/v2rayN/ServiceLib/Services/UpdateService.cs index 10c18f24..5a430a9c 100644 --- a/v2rayN/ServiceLib/Services/UpdateService.cs +++ b/v2rayN/ServiceLib/Services/UpdateService.cs @@ -114,7 +114,7 @@ namespace ServiceLib.Services _updateFunc?.Invoke(false, ResUI.MsgUpdateSubscriptionStart); var subItem = await AppHandler.Instance.SubItems(); - if (subItem == null || subItem.Count <= 0) + if (subItem is not { Count: > 0 }) { _updateFunc?.Invoke(false, ResUI.MsgNoValidSubscription); return; @@ -122,10 +122,10 @@ namespace ServiceLib.Services foreach (var item in subItem) { - string id = item.Id.TrimEx(); - string url = item.Url.TrimEx(); - string userAgent = item.UserAgent.TrimEx(); - string hashCode = $"{item.Remarks}->"; + var id = item.Id.TrimEx(); + var url = item.Url.TrimEx(); + var userAgent = item.UserAgent.TrimEx(); + var hashCode = $"{item.Remarks}->"; if (Utils.IsNullOrEmpty(id) || Utils.IsNullOrEmpty(url) || Utils.IsNotEmpty(subId) && item.Id != subId) { //_updateFunc?.Invoke(false, $"{hashCode}{ResUI.MsgNoValidSubscription}"); @@ -219,7 +219,7 @@ namespace ServiceLib.Services _updateFunc?.Invoke(false, $"{hashCode}{result}"); } - int ret = await ConfigHandler.AddBatchServers(config, result, id, true); + var ret = await ConfigHandler.AddBatchServers(config, result, id, true); if (ret <= 0) { Logging.SaveLog("FailedImportSubscription"); @@ -231,6 +231,8 @@ namespace ServiceLib.Services : $"{hashCode}{ResUI.MsgFailedImportSubscription}"); } _updateFunc?.Invoke(false, "-------------------------------------------------------"); + + await ConfigHandler.DedupServerList(config, id); } _updateFunc?.Invoke(true, $"{ResUI.MsgUpdateSubscriptionEnd}");