mirror of
https://github.com/songoda/EpicAnchors.git
synced 2024-11-29 05:26:13 +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.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@ -141,9 +142,9 @@ public class DataManager extends DataManagerAbstract {
|
||||
|
||||
SQLException err = null;
|
||||
|
||||
for (AnchorMigration.LegacyAnchorEntry entry : anchorEntries) {
|
||||
try (PreparedStatement ps = con.prepareStatement("INSERT INTO " + this.anchorTable +
|
||||
"(world_name,x,y,z, ticks_left) VALUES (?,?,?,?, ?);")) {
|
||||
try (PreparedStatement ps = con.prepareStatement("INSERT INTO " + this.anchorTable +
|
||||
"(world_name,x,y,z, ticks_left) VALUES (?,?,?,?, ?);")) {
|
||||
for (AnchorMigration.LegacyAnchorEntry entry : anchorEntries) {
|
||||
ps.setString(1, entry.worldName);
|
||||
ps.setInt(2, entry.x);
|
||||
ps.setInt(3, entry.y);
|
||||
@ -151,10 +152,18 @@ public class DataManager extends DataManagerAbstract {
|
||||
|
||||
ps.setInt(5, entry.ticksLeft);
|
||||
|
||||
ps.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
err = ex;
|
||||
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) {
|
||||
err = ex;
|
||||
}
|
||||
|
||||
if (err == null) {
|
||||
|
@ -6,13 +6,14 @@ import com.songoda.core.configuration.Config;
|
||||
import com.songoda.core.configuration.ConfigSetting;
|
||||
import com.songoda.core.hooks.EconomyManager;
|
||||
import com.songoda.epicanchors.EpicAnchors;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class Settings {
|
||||
private Settings() {
|
||||
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",
|
||||
"&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.utils.ThreadSync;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
@ -27,9 +27,7 @@ public class AnchorMigration extends DataMigrationManager {
|
||||
this.dataManager = dataManager;
|
||||
}
|
||||
|
||||
// TODO: Migration of a lot of Anchors takes **very** long (1100 anchors => 9 seconds)
|
||||
// This is easily fixed by putting all inserts into one big transaction but prevents us from
|
||||
public void migrateLegacyData(JavaPlugin plugin) {
|
||||
public void migrateLegacyData(Plugin plugin) {
|
||||
long start = System.nanoTime();
|
||||
|
||||
AtomicBoolean abortMigration = new AtomicBoolean(false);
|
||||
|
Loading…
Reference in New Issue
Block a user