Skip to content

Commit

Permalink
fix: performance of searching large config files
Browse files Browse the repository at this point in the history
  • Loading branch information
MSchmoecker committed Aug 12, 2024
1 parent 6ce5125 commit 5aa7e6d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Changelog

## Version 2.20.3
* Fixed explicit `AdminOnly = false` values to be locked for editing
* Fixed explicit `AdminOnly = false` config entries to be locked for editing
* Fixed performance when searching for config entries to sync in large config files

## Version 2.20.2
* Fixed adding admin-only configs between loading to the main menu and before loading the game being locked for local editing
Expand Down
16 changes: 8 additions & 8 deletions JotunnLib/Managers/SynchronizationManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class SynchronizationManager : IManager

private readonly Dictionary<string, bool> CachedAdminStates = new Dictionary<string, bool>();
private readonly Dictionary<string, ConfigFile> CustomConfigs = new Dictionary<string, ConfigFile>();
private List<Tuple<string, string, string, string>> CachedConfigValues = new List<Tuple<string, string, string, string>>();
private HashSet<Tuple<string, string, string, string>> CachedConfigValues = new HashSet<Tuple<string, string, string, string>>();
private readonly Dictionary<string, string> CachedCustomConfigGUIDs = new Dictionary<string, string>();
private BaseUnityPlugin ConfigurationManager;
private bool ConfigurationManagerWindowShown;
Expand Down Expand Up @@ -117,7 +117,7 @@ void IManager.Init()
return adminPkg;
});

AddInitialSynchronization(ConfigRPC, () => GenerateConfigZPackage(true, GetSyncConfigValues()));
AddInitialSynchronization(ConfigRPC, () => GenerateConfigZPackage(true, GetSyncConfigValues().ToList()));
}

/// <summary>
Expand Down Expand Up @@ -663,11 +663,11 @@ internal void CacheConfigurationValues()
/// Get syncable configuration values as tuples
/// </summary>
/// <returns></returns>
private List<Tuple<string, string, string, string>> GetSyncConfigValues()
private HashSet<Tuple<string, string, string, string>> GetSyncConfigValues()
{
Logger.LogDebug("Gathering config values");

var entries = new List<Tuple<string, string, string, string>>();
var entries = new HashSet<Tuple<string, string, string, string>>();
foreach (var config in GetConfigFiles())
{
string configIdentifier = GetFileIdentifier(config);
Expand Down Expand Up @@ -695,14 +695,14 @@ private List<Tuple<string, string, string, string>> GetSyncConfigValues()
internal void SynchronizeChangedConfig()
{
// Lets compare and send to server, if applicable
var valuesToSend = new List<Tuple<string, string, string, string>>();
var valuesToSend = new HashSet<Tuple<string, string, string, string>>();
foreach (var config in GetConfigFiles())
{
string configIdentifier = GetFileIdentifier(config);

foreach (var cd in config.Keys)
{
var cx = config[cd.Section, cd.Key];
var cx = config[cd];
var configAttribute = cx.GetConfigurationManagerAttributes();

if (configAttribute?.IsAdminOnly == true)
Expand All @@ -718,14 +718,14 @@ internal void SynchronizeChangedConfig()
}

// We need only changed values
valuesToSend = valuesToSend.Where(x => !CachedConfigValues.Contains(x)).ToList();
valuesToSend = new HashSet<Tuple<string, string, string, string>>(valuesToSend.Where(x => !CachedConfigValues.Contains(x)));

if (valuesToSend.Count > 0)
{
// Send if connected
if (ZNet.instance != null)
{
ZPackage package = GenerateConfigZPackage(false, valuesToSend);
ZPackage package = GenerateConfigZPackage(false, valuesToSend.ToList());

// Send values to server if it is a client instance
if (ZNet.instance.IsClientInstance())
Expand Down

0 comments on commit 5aa7e6d

Please sign in to comment.