Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #4498 build ServerState Assemblies collection in a more thread safe manner #4538

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions Oqtane.Server/Repository/ModuleDefinitionRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ private List<ModuleDefinition> ProcessModuleDefinitions(int siteId)
if (siteId != -1)
{
var siteKey = _tenants.GetAlias().SiteKey;
var assemblies = new List<string>();

// get all module definition permissions for site
List<Permission> permissions = _permissions.GetPermissions(siteId, EntityNames.ModuleDefinition).ToList();
Expand All @@ -193,7 +194,6 @@ private List<ModuleDefinition> ProcessModuleDefinitions(int siteId)
var settings = _settings.GetSettings(EntityNames.ModuleDefinition).ToList();

// populate module definition site settings and permissions
var serverState = _serverState.GetServerState(siteKey);
foreach (ModuleDefinition moduledefinition in ModuleDefinitions)
{
moduledefinition.SiteId = siteId;
Expand All @@ -211,17 +211,17 @@ private List<ModuleDefinition> ProcessModuleDefinitions(int siteId)
if (moduledefinition.IsEnabled)
{
// build list of assemblies for site
if (!serverState.Assemblies.Contains(moduledefinition.AssemblyName))
if (!assemblies.Contains(moduledefinition.AssemblyName))
{
serverState.Assemblies.Add(moduledefinition.AssemblyName);
assemblies.Add(moduledefinition.AssemblyName);
}
if (!string.IsNullOrEmpty(moduledefinition.Dependencies))
{
foreach (var assembly in moduledefinition.Dependencies.Replace(".dll", "").Split(',', StringSplitOptions.RemoveEmptyEntries).Reverse())
{
if (!serverState.Assemblies.Contains(assembly.Trim()))
if (!assemblies.Contains(assembly.Trim()))
{
serverState.Assemblies.Insert(0, assembly.Trim());
assemblies.Insert(0, assembly.Trim());
}
}
}
Expand All @@ -248,6 +248,13 @@ private List<ModuleDefinition> ProcessModuleDefinitions(int siteId)
}
}

// cache site assemblies
var serverState = _serverState.GetServerState(siteKey);
foreach (var assembly in assemblies)
{
if (!serverState.Assemblies.Contains(assembly)) serverState.Assemblies.Add(assembly);
}

// clean up any orphaned permissions
var ids = new HashSet<int>(ModuleDefinitions.Select(item => item.ModuleDefinitionId));
foreach (var permission in permissions.Where(item => !ids.Contains(item.EntityId)))
Expand Down
17 changes: 12 additions & 5 deletions Oqtane.Server/Repository/ThemeRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@ private List<Theme> ProcessThemes(int siteId)
if (siteId != -1)
{
var siteKey = _tenants.GetAlias().SiteKey;
var assemblies = new List<string>();

// get settings for site
var settings = _settings.GetSettings(EntityNames.Theme).ToList();

// populate theme site settings
var serverState = _serverState.GetServerState(siteKey);
foreach (Theme theme in Themes)
{
theme.SiteId = siteId;
Expand All @@ -184,22 +184,29 @@ private List<Theme> ProcessThemes(int siteId)
if (theme.IsEnabled)
{
// build list of assemblies for site
if (!serverState.Assemblies.Contains(theme.AssemblyName))
if (!assemblies.Contains(theme.AssemblyName))
{
serverState.Assemblies.Add(theme.AssemblyName);
assemblies.Add(theme.AssemblyName);
}
if (!string.IsNullOrEmpty(theme.Dependencies))
{
foreach (var assembly in theme.Dependencies.Replace(".dll", "").Split(',', StringSplitOptions.RemoveEmptyEntries).Reverse())
{
if (!serverState.Assemblies.Contains(assembly.Trim()))
if (!assemblies.Contains(assembly.Trim()))
{
serverState.Assemblies.Insert(0, assembly.Trim());
assemblies.Insert(0, assembly.Trim());
}
}
}
}
}

// cache site assemblies
var serverState = _serverState.GetServerState(siteKey);
foreach (var assembly in assemblies)
{
if (!serverState.Assemblies.Contains(assembly)) serverState.Assemblies.Add(assembly);
}
}

return Themes;
Expand Down