mirror of
https://github.com/songoda/EpicAnchors.git
synced 2024-12-01 14:33:25 +01:00
Vastly increase legacy data migration speed
Going from 9 seconds to 486ms a
This commit is contained in:
parent
431005e01a
commit
db4cc5944f
@ -17,6 +17,7 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.sql.Statement;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -141,9 +142,9 @@ public class DataManager extends DataManagerAbstract {
|
|||||||
|
|
||||||
SQLException err = null;
|
SQLException err = null;
|
||||||
|
|
||||||
for (AnchorMigration.LegacyAnchorEntry entry : anchorEntries) {
|
|
||||||
try (PreparedStatement ps = con.prepareStatement("INSERT INTO " + this.anchorTable +
|
try (PreparedStatement ps = con.prepareStatement("INSERT INTO " + this.anchorTable +
|
||||||
"(world_name,x,y,z, ticks_left) VALUES (?,?,?,?, ?);")) {
|
"(world_name,x,y,z, ticks_left) VALUES (?,?,?,?, ?);")) {
|
||||||
|
for (AnchorMigration.LegacyAnchorEntry entry : anchorEntries) {
|
||||||
ps.setString(1, entry.worldName);
|
ps.setString(1, entry.worldName);
|
||||||
ps.setInt(2, entry.x);
|
ps.setInt(2, entry.x);
|
||||||
ps.setInt(3, entry.y);
|
ps.setInt(3, entry.y);
|
||||||
@ -151,11 +152,19 @@ public class DataManager extends DataManagerAbstract {
|
|||||||
|
|
||||||
ps.setInt(5, entry.ticksLeft);
|
ps.setInt(5, entry.ticksLeft);
|
||||||
|
|
||||||
ps.executeUpdate();
|
ps.addBatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
int[] batchRes = ps.executeBatch();
|
||||||
|
|
||||||
|
for (int i : batchRes) {
|
||||||
|
if (i < 0 && i != Statement.SUCCESS_NO_INFO) {
|
||||||
|
throw new AssertionError("Batch-INSERT failed for at least one statement with code " + i + "");
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
err = ex;
|
err = ex;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (err == null) {
|
if (err == null) {
|
||||||
con.commit();
|
con.commit();
|
||||||
|
@ -6,13 +6,14 @@ import com.songoda.core.configuration.Config;
|
|||||||
import com.songoda.core.configuration.ConfigSetting;
|
import com.songoda.core.configuration.ConfigSetting;
|
||||||
import com.songoda.core.hooks.EconomyManager;
|
import com.songoda.core.hooks.EconomyManager;
|
||||||
import com.songoda.epicanchors.EpicAnchors;
|
import com.songoda.epicanchors.EpicAnchors;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public class Settings {
|
public class Settings {
|
||||||
private Settings() {
|
private Settings() {
|
||||||
throw new IllegalStateException("Utility class");
|
throw new IllegalStateException("Utility class");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Config config = EpicAnchors.getPlugin(EpicAnchors.class).getCoreConfig();
|
public static final Config config = JavaPlugin.getPlugin(EpicAnchors.class).getCoreConfig();
|
||||||
|
|
||||||
public static final ConfigSetting NAME_TAG = new ConfigSetting(config, "Main.Name Tag",
|
public static final ConfigSetting NAME_TAG = new ConfigSetting(config, "Main.Name Tag",
|
||||||
"&6Anchor &8(&7{REMAINING}&8)",
|
"&6Anchor &8(&7{REMAINING}&8)",
|
||||||
|
@ -8,7 +8,7 @@ import com.songoda.core.database.DatabaseConnector;
|
|||||||
import com.songoda.epicanchors.files.DataManager;
|
import com.songoda.epicanchors.files.DataManager;
|
||||||
import com.songoda.epicanchors.utils.ThreadSync;
|
import com.songoda.epicanchors.utils.ThreadSync;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@ -27,9 +27,7 @@ public class AnchorMigration extends DataMigrationManager {
|
|||||||
this.dataManager = dataManager;
|
this.dataManager = dataManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Migration of a lot of Anchors takes **very** long (1100 anchors => 9 seconds)
|
public void migrateLegacyData(Plugin plugin) {
|
||||||
// This is easily fixed by putting all inserts into one big transaction but prevents us from
|
|
||||||
public void migrateLegacyData(JavaPlugin plugin) {
|
|
||||||
long start = System.nanoTime();
|
long start = System.nanoTime();
|
||||||
|
|
||||||
AtomicBoolean abortMigration = new AtomicBoolean(false);
|
AtomicBoolean abortMigration = new AtomicBoolean(false);
|
||||||
|
Loading…
Reference in New Issue
Block a user