config manager: throttle config saves to file

When the default config is applied it queues a lot of saves to disk that
are unnecessary
This commit is contained in:
Adam
2019-03-11 09:04:33 -04:00
parent 167cc53cc1
commit 6371a7dd0b

View File

@@ -99,6 +99,9 @@ public class ConfigManager
public final void switchSession(AccountSession session)
{
// Ensure existing config is saved
sendConfig();
if (session == null)
{
this.session = null;
@@ -315,7 +318,7 @@ public class ConfigManager
}
}
private synchronized void saveToFile(final File propertiesFile) throws IOException
private void saveToFile(final File propertiesFile) throws IOException
{
propertiesFile.getParentFile().mkdirs();
@@ -392,19 +395,6 @@ public class ConfigManager
pendingChanges.put(groupName + "." + key, value);
}
Runnable task = () ->
{
try
{
saveToFile(propertiesFile);
}
catch (IOException ex)
{
log.warn("unable to save configuration file", ex);
}
};
executor.execute(task);
ConfigChanged configChanged = new ConfigChanged();
configChanged.setGroup(groupName);
configChanged.setKey(key);
@@ -435,19 +425,6 @@ public class ConfigManager
pendingChanges.put(groupName + "." + key, null);
}
Runnable task = () ->
{
try
{
saveToFile(propertiesFile);
}
catch (IOException ex)
{
log.warn("unable to save configuration file", ex);
}
};
executor.execute(task);
ConfigChanged configChanged = new ConfigChanged();
configChanged.setGroup(groupName);
configChanged.setKey(key);
@@ -653,6 +630,7 @@ public class ConfigManager
public void sendConfig()
{
boolean changed;
synchronized (pendingChanges)
{
if (client != null)
@@ -672,7 +650,20 @@ public class ConfigManager
}
}
}
changed = !pendingChanges.isEmpty();
pendingChanges.clear();
}
if (changed)
{
try
{
saveToFile(propertiesFile);
}
catch (IOException ex)
{
log.warn("unable to save configuration file", ex);
}
}
}
}