Allow test group

This commit is contained in:
DHR60 2026-02-27 22:09:11 +08:00
parent 23a04e9308
commit f7dbc5a995
5 changed files with 26 additions and 23 deletions

View file

@ -230,7 +230,7 @@ public sealed class AppManager
return await SQLiteHelper.Instance.TableAsync<ProfileItem>().FirstOrDefaultAsync(it => it.IndexId == indexId); return await SQLiteHelper.Instance.TableAsync<ProfileItem>().FirstOrDefaultAsync(it => it.IndexId == indexId);
} }
public async Task<List<ProfileItem>> GetProfileItemsByIndexIds(IEnumerable<string> indexIds) public async Task<List<ProfileItem>> GetProfileItemsByIndexIdsAsync(IEnumerable<string> indexIds)
{ {
var ids = indexIds.Where(id => !id.IsNullOrEmpty()).Distinct().ToList(); var ids = indexIds.Where(id => !id.IsNullOrEmpty()).Distinct().ToList();
if (ids.Count == 0) if (ids.Count == 0)
@ -242,6 +242,12 @@ public sealed class AppManager
.ToListAsync(); .ToListAsync();
} }
public async Task<Dictionary<string, ProfileItem>> GetProfileItemsByIndexIdsAsMapAsync(IEnumerable<string> indexIds)
{
var items = await GetProfileItemsByIndexIdsAsync(indexIds);
return items.ToDictionary(it => it.IndexId);
}
public async Task<ProfileItem?> GetProfileItemViaRemarks(string? remarks) public async Task<ProfileItem?> GetProfileItemViaRemarks(string? remarks)
{ {
if (remarks.IsNullOrEmpty()) if (remarks.IsNullOrEmpty())

View file

@ -103,16 +103,7 @@ public class GroupProfileManager
return []; return [];
} }
var childProfiles = await AppManager.Instance.GetProfileItemsByIndexIds(childProfileIds); var profileMap = await AppManager.Instance.GetProfileItemsByIndexIdsAsMapAsync(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 ordered = new List<ProfileItem>(childProfileIds.Count); var ordered = new List<ProfileItem>(childProfileIds.Count);
foreach (var id in childProfileIds) foreach (var id in childProfileIds)

View file

@ -149,11 +149,11 @@ public partial class CoreConfigSingboxService(CoreConfigContext context)
foreach (var it in selecteds) foreach (var it in selecteds)
{ {
if (!Global.SingboxSupportConfigType.Contains(it.ConfigType)) if (!(Global.XraySupportConfigType.Contains(it.ConfigType) || it.ConfigType.IsGroupType()))
{ {
continue; continue;
} }
if (it.Port <= 0) if (!it.ConfigType.IsComplexType() && it.Port <= 0)
{ {
continue; continue;
} }

View file

@ -112,11 +112,11 @@ public partial class CoreConfigV2rayService(CoreConfigContext context)
foreach (var it in selecteds) foreach (var it in selecteds)
{ {
if (!Global.XraySupportConfigType.Contains(it.ConfigType)) if (!(Global.XraySupportConfigType.Contains(it.ConfigType) || it.ConfigType.IsGroupType()))
{ {
continue; continue;
} }
if (it.Port <= 0) if (!it.ConfigType.IsComplexType() && it.Port <= 0)
{ {
continue; continue;
} }
@ -180,13 +180,13 @@ public partial class CoreConfigV2rayService(CoreConfigContext context)
//rule //rule
RulesItem4Ray rule = new() RulesItem4Ray rule = new()
{ {
inboundTag = new List<string> { inbound.tag }, inboundTag = [inbound.tag],
outboundTag = tag, outboundTag = tag,
type = "field" type = "field"
}; };
if (isBalancer) if (isBalancer)
{ {
rule.balancerTag = tag; rule.balancerTag = tag + Global.BalancerTagSuffix;
rule.outboundTag = null; rule.outboundTag = null;
} }
_coreConfig.routing.rules.Add(rule); _coreConfig.routing.rules.Add(rule);

View file

@ -61,21 +61,27 @@ public class SpeedtestService(Config config, Func<SpeedTestResult, Task> updateF
private async Task<List<ServerTestItem>> GetClearItem(ESpeedActionType actionType, List<ProfileItem> selecteds) private async Task<List<ServerTestItem>> GetClearItem(ESpeedActionType actionType, List<ProfileItem> selecteds)
{ {
var lstSelected = new List<ServerTestItem>(); var lstSelected = new List<ServerTestItem>(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++) for (var i = 0; i < selecteds.Count; i++)
{ {
var it = selecteds[i]; var it = selecteds[i];
if (it.ConfigType.IsComplexType()) if (it.ConfigType == EConfigType.Custom)
{ {
continue; continue;
} }
if (it.Port <= 0) if (!it.ConfigType.IsComplexType() && it.Port <= 0)
{ {
continue; continue;
} }
var profile = await AppManager.Instance.GetProfileItem(it.IndexId) ?? it; var profile = profileMap.GetValueOrDefault(it.IndexId, it);
lstSelected.Add(new ServerTestItem() lstSelected.Add(new ServerTestItem()
{ {
IndexId = it.IndexId, IndexId = it.IndexId,
@ -357,8 +363,8 @@ public class SpeedtestService(Config config, Func<SpeedTestResult, Task> updateF
private List<List<ServerTestItem>> GetTestBatchItem(List<ServerTestItem> lstSelected, int pageSize) private List<List<ServerTestItem>> GetTestBatchItem(List<ServerTestItem> lstSelected, int pageSize)
{ {
List<List<ServerTestItem>> lstTest = new(); List<List<ServerTestItem>> lstTest = new();
var lst1 = lstSelected.Where(t => Global.XraySupportConfigType.Contains(t.ConfigType) && t.CoreType == ECoreType.Xray).ToList(); var lst1 = lstSelected.Where(t => t.CoreType == ECoreType.Xray).ToList();
var lst2 = lstSelected.Where(t => Global.SingboxSupportConfigType.Contains(t.ConfigType) && t.CoreType == ECoreType.sing_box).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++) for (var num = 0; num < (int)Math.Ceiling(lst1.Count * 1.0 / pageSize); num++)
{ {