From e9a6411698377a407f3507a21dc80ca2bc53d64a Mon Sep 17 00:00:00 2001 From: DHR60 Date: Mon, 9 Feb 2026 10:17:42 +0800 Subject: [PATCH] Fix order --- .../ServiceLib/Manager/GroupProfileManager.cs | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/v2rayN/ServiceLib/Manager/GroupProfileManager.cs b/v2rayN/ServiceLib/Manager/GroupProfileManager.cs index cad0c13c..5e87f0e6 100644 --- a/v2rayN/ServiceLib/Manager/GroupProfileManager.cs +++ b/v2rayN/ServiceLib/Manager/GroupProfileManager.cs @@ -96,9 +96,34 @@ public class GroupProfileManager return []; } var childProfileIds = Utils.String2List(extra.ChildItems) - ?.Where(p => !string.IsNullOrEmpty(p)) ?? []; + ?.Where(p => !string.IsNullOrEmpty(p)) + .ToList() ?? []; + if (childProfileIds.Count == 0) + { + return []; + } + var childProfiles = await AppManager.Instance.GetProfileItemsByIndexIds(childProfileIds); - return childProfiles ?? []; + 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(childProfileIds.Count); + foreach (var id in childProfileIds) + { + if (id != null && profileMap.TryGetValue(id, out var item) && item != null) + { + ordered.Add(item); + } + } + + return ordered; } private static async Task> GetSubChildProfileItems(ProtocolExtraItem? extra)