From 88ac19af7646b16aa4d895acd7c2b47046ab64d4 Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Sun, 1 Mar 2026 12:39:49 +0800 Subject: [PATCH] Refactor non-global plugin retrieval for performance optimization Refactored plugin lookup in ValidPluginsForQuery to use a new TryGetNonGlobalPlugins method, which safely copies plugin lists using a lock. This improves thread safety and performance when accessing non-global plugins. --- Flow.Launcher.Core/Plugin/PluginManager.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher.Core/Plugin/PluginManager.cs b/Flow.Launcher.Core/Plugin/PluginManager.cs index 199d4e7b1..e6b2bc2a2 100644 --- a/Flow.Launcher.Core/Plugin/PluginManager.cs +++ b/Flow.Launcher.Core/Plugin/PluginManager.cs @@ -380,7 +380,7 @@ namespace Flow.Launcher.Core.Plugin if (query is null) return Array.Empty(); - if (!GetNonGlobalPlugins().TryGetValue(query.ActionKeyword, out var plugins)) + if (TryGetNonGlobalPlugins(query.ActionKeyword, out var plugins)) { if (dialogJump) return [.. GetGlobalPlugins().Where(p => p.Plugin is IAsyncDialogJump && !PluginModified(p.Metadata.ID))]; @@ -395,6 +395,20 @@ namespace Flow.Launcher.Core.Plugin return [.. validPlugins]; } + private static bool TryGetNonGlobalPlugins(string actionKeyword, out List plugins) + { + if (_nonGlobalPlugins.TryGetValue(actionKeyword, out var list)) + { + lock (list) + { + plugins = [.. list]; + } + return true; + } + plugins = []; + return false; + } + public static ICollection ValidPluginsForHomeQuery() { return [.. _homePlugins.Where(p => !PluginModified(p.Metadata.ID))];