mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-01-27 02:21:30 +01:00
[#861] server-network config system now stores last modified date instead
This prevents unnecessary config update after it is saved into the db
This commit is contained in:
parent
88fd623718
commit
d6ef6ec566
@ -85,5 +85,5 @@ public interface SaveOperations {
|
||||
|
||||
void setAsUninstalled(UUID serverUUID);
|
||||
|
||||
void saveConfig(UUID serverUUID, Config config);
|
||||
void saveConfig(UUID serverUUID, Config config, long lastModified);
|
||||
}
|
@ -155,7 +155,7 @@ public class SQLSaveOps extends SQLOps implements SaveOperations {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveConfig(UUID serverUUID, Config config) {
|
||||
settingsTable.storeConfig(serverUUID, config);
|
||||
public void saveConfig(UUID serverUUID, Config config, long lastModified) {
|
||||
settingsTable.storeConfig(serverUUID, config, lastModified);
|
||||
}
|
||||
}
|
||||
|
@ -66,22 +66,23 @@ public class SettingsTable extends Table {
|
||||
* <p>
|
||||
* Only one config is stored per server uuid.
|
||||
*
|
||||
* @param serverUUID UUID of the server.
|
||||
* @param config Config of the server.
|
||||
* @param serverUUID UUID of the server.
|
||||
* @param config Config of the server.
|
||||
* @param lastModified Epoch ms the config file was last modified.
|
||||
*/
|
||||
public void storeConfig(UUID serverUUID, Config config) {
|
||||
public void storeConfig(UUID serverUUID, Config config, long lastModified) {
|
||||
TextStringBuilder configTextBuilder = new TextStringBuilder();
|
||||
List<String> lines = new ConfigWriter().parseLines(config);
|
||||
configTextBuilder.appendWithSeparators(lines, "\n");
|
||||
String configSettings = configTextBuilder.toString();
|
||||
if (isConfigStored(serverUUID)) {
|
||||
updateConfig(serverUUID, configSettings);
|
||||
updateConfig(serverUUID, configSettings, lastModified);
|
||||
} else {
|
||||
insertConfig(serverUUID, configSettings);
|
||||
insertConfig(serverUUID, configSettings, lastModified);
|
||||
}
|
||||
}
|
||||
|
||||
private void insertConfig(UUID serverUUID, String configSettings) {
|
||||
private void insertConfig(UUID serverUUID, String configSettings, long lastModified) {
|
||||
String sql = "INSERT INTO " + tableName + " (" +
|
||||
Col.SERVER_UUID + ", " +
|
||||
Col.UPDATED + ", " +
|
||||
@ -91,13 +92,13 @@ public class SettingsTable extends Table {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, serverUUID.toString());
|
||||
statement.setLong(2, System.currentTimeMillis());
|
||||
statement.setLong(2, lastModified);
|
||||
statement.setString(3, configSettings);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateConfig(UUID serverUUID, String configSettings) {
|
||||
private void updateConfig(UUID serverUUID, String configSettings, long lastModified) {
|
||||
String sql = "UPDATE " + tableName + " SET " +
|
||||
Col.CONFIG_CONTENT + "=?," +
|
||||
Col.UPDATED + "=? WHERE " +
|
||||
@ -108,7 +109,7 @@ public class SettingsTable extends Table {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, configSettings);
|
||||
statement.setLong(2, System.currentTimeMillis());
|
||||
statement.setLong(2, lastModified);
|
||||
statement.setString(3, serverUUID.toString());
|
||||
statement.setString(4, configSettings);
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ public class NetworkSettingManager implements SubSystem {
|
||||
|
||||
try (ConfigReader reader = new ConfigReader(file.toPath())) {
|
||||
Config config = reader.read();
|
||||
database.save().saveConfig(serverUUID, config);
|
||||
database.save().saveConfig(serverUUID, config, file.lastModified());
|
||||
String serverName = config.getNode(PluginSettings.SERVER_NAME.getPath()).map(ConfigNode::getString).orElse("Unknown");
|
||||
logger.debug("Server config '" + serverName + "' in db now up to date.");
|
||||
} catch (IOException e) {
|
||||
|
@ -109,7 +109,7 @@ public class ServerSettingsManager implements SubSystem {
|
||||
|
||||
try (ConfigReader reader = new ConfigReader(file.toPath())) {
|
||||
Config config = reader.read();
|
||||
database.save().saveConfig(serverInfo.getServerUUID(), config);
|
||||
database.save().saveConfig(serverInfo.getServerUUID(), config, file.lastModified());
|
||||
logger.debug("Server config saved to database.");
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
|
@ -17,6 +17,7 @@
|
||||
package com.djrapitops.plan.system.tasks.server;
|
||||
|
||||
import com.djrapitops.plan.system.database.DBSystem;
|
||||
import com.djrapitops.plan.system.file.PlanFiles;
|
||||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
@ -33,6 +34,7 @@ import javax.inject.Singleton;
|
||||
@Singleton
|
||||
public class ConfigStoreTask extends AbsRunnable {
|
||||
|
||||
private final PlanFiles files;
|
||||
private final PlanConfig config;
|
||||
private final ServerInfo serverInfo;
|
||||
private final DBSystem dbSystem;
|
||||
@ -40,11 +42,13 @@ public class ConfigStoreTask extends AbsRunnable {
|
||||
|
||||
@Inject
|
||||
public ConfigStoreTask(
|
||||
PlanFiles files,
|
||||
PlanConfig config,
|
||||
ServerInfo serverInfo,
|
||||
DBSystem dbSystem,
|
||||
PluginLogger logger
|
||||
) {
|
||||
this.files = files;
|
||||
this.config = config;
|
||||
this.serverInfo = serverInfo;
|
||||
this.dbSystem = dbSystem;
|
||||
@ -53,7 +57,8 @@ public class ConfigStoreTask extends AbsRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
dbSystem.getDatabase().save().saveConfig(serverInfo.getServerUUID(), config);
|
||||
long lastModified = files.getConfigFile().lastModified();
|
||||
dbSystem.getDatabase().save().saveConfig(serverInfo.getServerUUID(), config, lastModified);
|
||||
logger.debug("Config Store Task - Config in db now up to date.");
|
||||
cancel();
|
||||
}
|
||||
|
@ -1039,7 +1039,7 @@ public abstract class CommonDBTest {
|
||||
PlanConfig config = system.getConfigSystem().getConfig();
|
||||
|
||||
SettingsTable settingsTable = db.getSettingsTable();
|
||||
settingsTable.storeConfig(serverUUID, config);
|
||||
settingsTable.storeConfig(serverUUID, config, System.currentTimeMillis());
|
||||
|
||||
Optional<Config> foundConfig = settingsTable.fetchNewerConfig(0, serverUUID);
|
||||
assertTrue(foundConfig.isPresent());
|
||||
@ -1054,7 +1054,7 @@ public abstract class CommonDBTest {
|
||||
PlanConfig config = system.getConfigSystem().getConfig();
|
||||
|
||||
SettingsTable settingsTable = db.getSettingsTable();
|
||||
settingsTable.storeConfig(serverUUID, config);
|
||||
settingsTable.storeConfig(serverUUID, config, System.currentTimeMillis());
|
||||
|
||||
assertFalse(settingsTable.fetchNewerConfig(savedMs, serverUUID).isPresent());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user