From 84a1eb8445e9d99bd4d19352f50125f850b723f2 Mon Sep 17 00:00:00 2001 From: DHR60 Date: Sat, 7 Feb 2026 21:58:10 +0800 Subject: [PATCH] Optimize ProfileItem acquisition speed --- v2rayN/ServiceLib/Handler/CoreConfigHandler.cs | 4 ++-- v2rayN/ServiceLib/Manager/AppManager.cs | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/v2rayN/ServiceLib/Handler/CoreConfigHandler.cs b/v2rayN/ServiceLib/Handler/CoreConfigHandler.cs index 0db0b9b7..9260fa11 100644 --- a/v2rayN/ServiceLib/Handler/CoreConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/CoreConfigHandler.cs @@ -98,9 +98,9 @@ public static class CoreConfigHandler var ids = selecteds.Where(serverTestItem => !serverTestItem.IndexId.IsNullOrEmpty()) .Select(serverTestItem => serverTestItem.IndexId!) .ToList(); - foreach (var id in ids) + var nodes = await AppManager.Instance.GetProfileItemsByIndexIds(ids); + foreach (var node in nodes) { - var node = await AppManager.Instance.GetProfileItem(id) ?? new(); await FillNodeContext(context, node, false); } if (coreType == ECoreType.sing_box) diff --git a/v2rayN/ServiceLib/Manager/AppManager.cs b/v2rayN/ServiceLib/Manager/AppManager.cs index 0e471568..82eec00e 100644 --- a/v2rayN/ServiceLib/Manager/AppManager.cs +++ b/v2rayN/ServiceLib/Manager/AppManager.cs @@ -230,6 +230,18 @@ public sealed class AppManager return await SQLiteHelper.Instance.TableAsync().FirstOrDefaultAsync(it => it.IndexId == indexId); } + public async Task> GetProfileItemsByIndexIds(List indexIds) + { + var ids = indexIds.Where(id => id.IsNotEmpty()).Distinct().ToList(); + if (ids.Count == 0) + { + return []; + } + return await SQLiteHelper.Instance.TableAsync() + .Where(it => ids.Contains(it.IndexId)) + .ToListAsync(); + } + public async Task GetProfileItemViaRemarks(string? remarks) { if (remarks.IsNullOrEmpty())