mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-08-20 20:12:57 +00:00
Avoid modification of the list while iterating over it
This commit is contained in:
parent
80c1d72ca2
commit
589d62c9ce
@ -44,8 +44,8 @@ public sealed record PluginConfigurationObject
|
|||||||
IList<IAvailablePlugin> availablePlugins,
|
IList<IAvailablePlugin> availablePlugins,
|
||||||
IList<PluginConfigurationObject> configObjectList) where TClass : IConfigurationObject
|
IList<PluginConfigurationObject> configObjectList) where TClass : IConfigurationObject
|
||||||
{
|
{
|
||||||
var wasConfigurationChanged = false;
|
|
||||||
var configuredObjects = configObjectSelection.Compile()(SETTINGS_MANAGER.ConfigurationData);
|
var configuredObjects = configObjectSelection.Compile()(SETTINGS_MANAGER.ConfigurationData);
|
||||||
|
var leftOverObjects = new List<TClass>();
|
||||||
foreach (var configuredObject in configuredObjects)
|
foreach (var configuredObject in configuredObjects)
|
||||||
{
|
{
|
||||||
if(!configuredObject.IsEnterpriseConfiguration)
|
if(!configuredObject.IsEnterpriseConfiguration)
|
||||||
@ -59,8 +59,7 @@ public sealed record PluginConfigurationObject
|
|||||||
if(templateSourcePlugin is null)
|
if(templateSourcePlugin is null)
|
||||||
{
|
{
|
||||||
LOG.LogWarning($"The configured object '{configuredObject.Name}' (id={configuredObject.Id}) is based on a plugin that is not available anymore. Removing the chat template from the settings.");
|
LOG.LogWarning($"The configured object '{configuredObject.Name}' (id={configuredObject.Id}) is based on a plugin that is not available anymore. Removing the chat template from the settings.");
|
||||||
configuredObjects.Remove(configuredObject);
|
leftOverObjects.Add(configuredObject);
|
||||||
wasConfigurationChanged = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!configObjectList.Any(configObject =>
|
if(!configObjectList.Any(configObject =>
|
||||||
@ -69,11 +68,15 @@ public sealed record PluginConfigurationObject
|
|||||||
configObject.Id.ToString() == configuredObject.Id))
|
configObject.Id.ToString() == configuredObject.Id))
|
||||||
{
|
{
|
||||||
LOG.LogWarning($"The configured object '{configuredObject.Name}' (id={configuredObject.Id}) is not present in the configuration plugin anymore. Removing the chat template from the settings.");
|
LOG.LogWarning($"The configured object '{configuredObject.Name}' (id={configuredObject.Id}) is not present in the configuration plugin anymore. Removing the chat template from the settings.");
|
||||||
configuredObjects.Remove(configuredObject);
|
leftOverObjects.Add(configuredObject);
|
||||||
wasConfigurationChanged = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove collected items after enumeration to avoid modifying the collection during iteration:
|
||||||
|
var wasConfigurationChanged = leftOverObjects.Count > 0;
|
||||||
|
foreach (var item in leftOverObjects.Distinct())
|
||||||
|
configuredObjects.Remove(item);
|
||||||
|
|
||||||
return wasConfigurationChanged;
|
return wasConfigurationChanged;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user