prevent double-lookup for dev plugins in non-default profiles

This commit is contained in:
goaaats 2024-01-19 23:42:44 +01:00
parent 4e95d4fe37
commit 57b8a5d932
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B

View file

@ -1494,6 +1494,8 @@ internal partial class PluginManager : IDisposable, IServiceType
throw new Exception("Plugin should have a WorkingPluginId at this point"); throw new Exception("Plugin should have a WorkingPluginId at this point");
this.profileManager.MigrateProfilesToGuidsForPlugin(plugin.Manifest.InternalName, plugin.Manifest.WorkingPluginId); this.profileManager.MigrateProfilesToGuidsForPlugin(plugin.Manifest.InternalName, plugin.Manifest.WorkingPluginId);
var wantedByAnyProfile = false;
// Now, if this is a devPlugin, figure out if we want to load it // Now, if this is a devPlugin, figure out if we want to load it
if (isDev) if (isDev)
{ {
@ -1508,13 +1510,12 @@ internal partial class PluginManager : IDisposable, IServiceType
// The code below will take care of it and add it with the default value. // The code below will take care of it and add it with the default value.
Log.Verbose("DevPlugin {Name} not wanted in default plugin", plugin.Manifest.InternalName); Log.Verbose("DevPlugin {Name} not wanted in default plugin", plugin.Manifest.InternalName);
// If it is wanted by any other plugin, we do want to load it. This means we are looking it up twice, but I don't care right now. // Check if any profile wants this plugin. We need to do this here, since we want to allow loading a dev plugin if a non-default profile wants it active.
// I am putting a TODO so that goat will clean it up some day soon. // Note that this will not add the plugin to the default profile. That's done below in any other case.
if (await this.profileManager.GetWantStateAsync( wantedByAnyProfile = await this.profileManager.GetWantStateAsync(plugin.Manifest.WorkingPluginId, plugin.Manifest.InternalName, false, false);
plugin.Manifest.WorkingPluginId,
plugin.Manifest.InternalName, // If it is wanted by any other profile, we do want to load it.
false, if (wantedByAnyProfile)
false))
loadPlugin = true; loadPlugin = true;
} }
else if (wantsInDefaultProfile == false && devPlugin.StartOnBoot) else if (wantsInDefaultProfile == false && devPlugin.StartOnBoot)
@ -1553,8 +1554,9 @@ internal partial class PluginManager : IDisposable, IServiceType
var defaultState = manifest?.Disabled != true && loadPlugin; var defaultState = manifest?.Disabled != true && loadPlugin;
#pragma warning restore CS0618 #pragma warning restore CS0618
// Need to do this here, so plugins that don't load are still added to the default profile // Plugins that aren't in any profile will be added to the default profile with this call.
var wantedByAnyProfile = await this.profileManager.GetWantStateAsync(plugin.Manifest.WorkingPluginId, plugin.Manifest.InternalName, defaultState); // We are skipping a double-lookup for dev plugins that are wanted by non-default profiles, as noted above.
wantedByAnyProfile = wantedByAnyProfile || await this.profileManager.GetWantStateAsync(plugin.Manifest.WorkingPluginId, plugin.Manifest.InternalName, defaultState);
Log.Information("{Name} defaultState: {State} wantedByAnyProfile: {WantedByAny} loadPlugin: {LoadPlugin}", plugin.Manifest.InternalName, defaultState, wantedByAnyProfile, loadPlugin); Log.Information("{Name} defaultState: {State} wantedByAnyProfile: {WantedByAny} loadPlugin: {LoadPlugin}", plugin.Manifest.InternalName, defaultState, wantedByAnyProfile, loadPlugin);
if (loadPlugin) if (loadPlugin)