Compare commits

..

2 commits

Author SHA1 Message Date
DHR60
eb42583819
Merge 6808595fa1 into 22f0d04f01 2025-10-03 09:12:04 +00:00
2dust
6808595fa1 Update ProfileGroupItem.cs 2025-10-03 17:11:56 +08:00
2 changed files with 47 additions and 1 deletions

View file

@ -1,4 +1,5 @@
using SQLite; using SQLite;
namespace ServiceLib.Models; namespace ServiceLib.Models;
[Serializable] [Serializable]
@ -10,4 +11,48 @@ public class ProfileGroupItem
public string ChildItems { get; set; } public string ChildItems { get; set; }
public EMultipleLoad MultipleLoad { get; set; } = EMultipleLoad.LeastPing; public EMultipleLoad MultipleLoad { get; set; } = EMultipleLoad.LeastPing;
public bool HasCycle()
{
return HasCycle(new HashSet<string>(), new HashSet<string>());
}
public bool HasCycle(HashSet<string> visited, HashSet<string> stack)
{
if (string.IsNullOrEmpty(ParentIndexId))
return false;
if (stack.Contains(ParentIndexId))
return true;
if (visited.Contains(ParentIndexId))
return false;
visited.Add(ParentIndexId);
stack.Add(ParentIndexId);
if (string.IsNullOrEmpty(ChildItems))
{
return false;
}
var childIds = Utils.String2List(ChildItems)
.Where(p => !string.IsNullOrEmpty(p))
.ToList();
var childProfiles = childIds.Select(ProfileGroupItemManager.Instance.GetOrDefault)//这里是内存访问
.Where(p => p != null)
.ToList();
foreach (var child in childProfiles)
{
if (child.HasCycle(visited, stack))
{
return true;
}
}
stack.Remove(ParentIndexId);
return false;
}
} }

View file

@ -496,7 +496,8 @@ public partial class CoreConfigV2rayService
return -1; return -1;
} }
var hasCycle = await node.HasCycle(new HashSet<string>(), new HashSet<string>()); var hasCycle = profileGroupItem.HasCycle();
//var hasCycle = await node.HasCycle(new HashSet<string>(), new HashSet<string>());
if (hasCycle) if (hasCycle)
{ {
return -1; return -1;