diff --git a/v2rayN/ServiceLib/Manager/AppManager.cs b/v2rayN/ServiceLib/Manager/AppManager.cs index e773c2ef..a913a2ae 100644 --- a/v2rayN/ServiceLib/Manager/AppManager.cs +++ b/v2rayN/ServiceLib/Manager/AppManager.cs @@ -230,7 +230,7 @@ public sealed class AppManager return await SQLiteHelper.Instance.TableAsync().FirstOrDefaultAsync(it => it.IndexId == indexId); } - public async Task> GetProfileItemsByIndexIds(IEnumerable indexIds) + public async Task> GetProfileItemsByIndexIdsAsync(IEnumerable indexIds) { var ids = indexIds.Where(id => !id.IsNullOrEmpty()).Distinct().ToList(); if (ids.Count == 0) @@ -242,6 +242,12 @@ public sealed class AppManager .ToListAsync(); } + public async Task> GetProfileItemsByIndexIdsAsMapAsync(IEnumerable indexIds) + { + var items = await GetProfileItemsByIndexIdsAsync(indexIds); + return items.ToDictionary(it => it.IndexId); + } + public async Task GetProfileItemViaRemarks(string? remarks) { if (remarks.IsNullOrEmpty()) diff --git a/v2rayN/ServiceLib/Manager/GroupProfileManager.cs b/v2rayN/ServiceLib/Manager/GroupProfileManager.cs index 5e87f0e6..90c6c9c2 100644 --- a/v2rayN/ServiceLib/Manager/GroupProfileManager.cs +++ b/v2rayN/ServiceLib/Manager/GroupProfileManager.cs @@ -103,16 +103,7 @@ public class GroupProfileManager return []; } - var childProfiles = await AppManager.Instance.GetProfileItemsByIndexIds(childProfileIds); - if (childProfiles == null || childProfiles.Count == 0) - { - return []; - } - - var profileMap = childProfiles - .Where(p => p != null && !p.IndexId.IsNullOrEmpty()) - .GroupBy(p => p!.IndexId!) - .ToDictionary(g => g.Key, g => g.First()); + var profileMap = await AppManager.Instance.GetProfileItemsByIndexIdsAsMapAsync(childProfileIds); var ordered = new List(childProfileIds.Count); foreach (var id in childProfileIds) diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/CoreConfigSingboxService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/CoreConfigSingboxService.cs index 87b59e11..68de524a 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/CoreConfigSingboxService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/CoreConfigSingboxService.cs @@ -149,11 +149,11 @@ public partial class CoreConfigSingboxService(CoreConfigContext context) foreach (var it in selecteds) { - if (!Global.SingboxSupportConfigType.Contains(it.ConfigType)) + if (!(Global.XraySupportConfigType.Contains(it.ConfigType) || it.ConfigType.IsGroupType())) { continue; } - if (it.Port <= 0) + if (!it.ConfigType.IsComplexType() && it.Port <= 0) { continue; } diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/CoreConfigV2rayService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/CoreConfigV2rayService.cs index e34dceb6..e5182c97 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/CoreConfigV2rayService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/CoreConfigV2rayService.cs @@ -112,11 +112,11 @@ public partial class CoreConfigV2rayService(CoreConfigContext context) foreach (var it in selecteds) { - if (!Global.XraySupportConfigType.Contains(it.ConfigType)) + if (!(Global.XraySupportConfigType.Contains(it.ConfigType) || it.ConfigType.IsGroupType())) { continue; } - if (it.Port <= 0) + if (!it.ConfigType.IsComplexType() && it.Port <= 0) { continue; } @@ -180,13 +180,13 @@ public partial class CoreConfigV2rayService(CoreConfigContext context) //rule RulesItem4Ray rule = new() { - inboundTag = new List { inbound.tag }, + inboundTag = [inbound.tag], outboundTag = tag, type = "field" }; if (isBalancer) { - rule.balancerTag = tag; + rule.balancerTag = tag + Global.BalancerTagSuffix; rule.outboundTag = null; } _coreConfig.routing.rules.Add(rule); diff --git a/v2rayN/ServiceLib/Services/SpeedtestService.cs b/v2rayN/ServiceLib/Services/SpeedtestService.cs index 9bacfda8..329d2212 100644 --- a/v2rayN/ServiceLib/Services/SpeedtestService.cs +++ b/v2rayN/ServiceLib/Services/SpeedtestService.cs @@ -61,21 +61,27 @@ public class SpeedtestService(Config config, Func updateF private async Task> GetClearItem(ESpeedActionType actionType, List selecteds) { - var lstSelected = new List(); + var lstSelected = new List(selecteds.Count); + var ids = selecteds.Where(it => !it.IndexId.IsNullOrEmpty() + && it.ConfigType != EConfigType.Custom + && (it.ConfigType.IsComplexType() || it.Port > 0)) + .Select(it => it.IndexId) + .ToList(); + var profileMap = await AppManager.Instance.GetProfileItemsByIndexIdsAsMapAsync(ids); for (var i = 0; i < selecteds.Count; i++) { var it = selecteds[i]; - if (it.ConfigType.IsComplexType()) + if (it.ConfigType == EConfigType.Custom) { continue; } - if (it.Port <= 0) + if (!it.ConfigType.IsComplexType() && it.Port <= 0) { continue; } - var profile = await AppManager.Instance.GetProfileItem(it.IndexId) ?? it; + var profile = profileMap.GetValueOrDefault(it.IndexId, it); lstSelected.Add(new ServerTestItem() { IndexId = it.IndexId, @@ -357,8 +363,8 @@ public class SpeedtestService(Config config, Func updateF private List> GetTestBatchItem(List lstSelected, int pageSize) { List> lstTest = new(); - var lst1 = lstSelected.Where(t => Global.XraySupportConfigType.Contains(t.ConfigType) && t.CoreType == ECoreType.Xray).ToList(); - var lst2 = lstSelected.Where(t => Global.SingboxSupportConfigType.Contains(t.ConfigType) && t.CoreType == ECoreType.sing_box).ToList(); + var lst1 = lstSelected.Where(t => t.CoreType == ECoreType.Xray).ToList(); + var lst2 = lstSelected.Where(t => t.CoreType == ECoreType.sing_box).ToList(); for (var num = 0; num < (int)Math.Ceiling(lst1.Count * 1.0 / pageSize); num++) {