forked from LogBlock/LogBlock
Reduce amount of string allocations
This commit is contained in:
@@ -710,9 +710,8 @@ public class Consumer extends Thread {
|
|||||||
public BlockRow(Location loc, Actor actor, int replaced, int replacedData, byte[] replacedState, int type, int typeData, byte[] typeState, ChestAccess ca) {
|
public BlockRow(Location loc, Actor actor, int replaced, int replacedData, byte[] replacedState, int type, int typeData, byte[] typeState, ChestAccess ca) {
|
||||||
super(System.currentTimeMillis() / 1000, loc, actor, replaced, replacedData, replacedState, type, typeData, typeState, ca);
|
super(System.currentTimeMillis() / 1000, loc, actor, replaced, replacedData, replacedState, type, typeData, typeState, ca);
|
||||||
|
|
||||||
final String table = getWorldConfig(loc.getWorld()).table;
|
statementString = getWorldConfig(loc.getWorld()).insertBlockStatementString;
|
||||||
statementString = "INSERT INTO `" + table + "-blocks` (date, playerid, replaced, replaceddata, type, typedata, x, y, z) VALUES (FROM_UNIXTIME(?), ?, ?, ?, ?, ?, ?, ?, ?)";
|
selectActorIdStatementString = getWorldConfig(loc.getWorld()).selectBlockActorIdStatementString;
|
||||||
selectActorIdStatementString = "SELECT playerid FROM `" + table + "-blocks` WHERE x = ? AND y = ? AND z = ? ORDER BY date DESC LIMIT 1";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -769,17 +768,16 @@ public class Consumer extends Thread {
|
|||||||
batchHelper.addBatch(smt, new IntCallback() {
|
batchHelper.addBatch(smt, new IntCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void call(int id) throws SQLException {
|
public void call(int id) throws SQLException {
|
||||||
final String table = getWorldConfig(loc.getWorld()).table;
|
|
||||||
PreparedStatement ps;
|
PreparedStatement ps;
|
||||||
if (typeState != null || replacedState != null) {
|
if (typeState != null || replacedState != null) {
|
||||||
ps = batchHelper.getOrPrepareStatement(conn, "INSERT INTO `" + table + "-state` (replacedState, typeState, id) VALUES(?, ?, ?)", Statement.NO_GENERATED_KEYS);
|
ps = batchHelper.getOrPrepareStatement(conn, getWorldConfig(loc.getWorld()).insertBlockStateStatementString, Statement.NO_GENERATED_KEYS);
|
||||||
ps.setBytes(1, replacedState);
|
ps.setBytes(1, replacedState);
|
||||||
ps.setBytes(2, typeState);
|
ps.setBytes(2, typeState);
|
||||||
ps.setInt(3, id);
|
ps.setInt(3, id);
|
||||||
batchHelper.addBatch(ps, null);
|
batchHelper.addBatch(ps, null);
|
||||||
}
|
}
|
||||||
if (ca != null) {
|
if (ca != null) {
|
||||||
ps = batchHelper.getOrPrepareStatement(conn, "INSERT INTO `" + table + "-chestdata` (item, itemremove, id, itemtype) values (?, ?, ?, ?)", Statement.NO_GENERATED_KEYS);
|
ps = batchHelper.getOrPrepareStatement(conn, getWorldConfig(loc.getWorld()).insertBlockChestDataStatementString, Statement.NO_GENERATED_KEYS);
|
||||||
ps.setBytes(1, Utils.saveItemStack(ca.itemStack));
|
ps.setBytes(1, Utils.saveItemStack(ca.itemStack));
|
||||||
ps.setInt(2, ca.remove ? 1 : 0);
|
ps.setInt(2, ca.remove ? 1 : 0);
|
||||||
ps.setInt(3, id);
|
ps.setInt(3, id);
|
||||||
|
@@ -12,6 +12,10 @@ import java.util.Map.Entry;
|
|||||||
public class WorldConfig extends LoggingEnabledMapping {
|
public class WorldConfig extends LoggingEnabledMapping {
|
||||||
public final String world;
|
public final String world;
|
||||||
public final String table;
|
public final String table;
|
||||||
|
public final String insertBlockStatementString;
|
||||||
|
public final String selectBlockActorIdStatementString;
|
||||||
|
public final String insertBlockStateStatementString;
|
||||||
|
public final String insertBlockChestDataStatementString;
|
||||||
|
|
||||||
public WorldConfig(String world, File file) throws IOException {
|
public WorldConfig(String world, File file) throws IOException {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
@@ -33,5 +37,10 @@ public class WorldConfig extends LoggingEnabledMapping {
|
|||||||
for (final Logging l : Logging.values()) {
|
for (final Logging l : Logging.values()) {
|
||||||
setLogging(l, config.getBoolean("logging." + l.toString()));
|
setLogging(l, config.getBoolean("logging." + l.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
insertBlockStatementString = "INSERT INTO `" + table + "-blocks` (date, playerid, replaced, replaceddata, type, typedata, x, y, z) VALUES (FROM_UNIXTIME(?), ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
|
selectBlockActorIdStatementString = "SELECT playerid FROM `" + table + "-blocks` WHERE x = ? AND y = ? AND z = ? ORDER BY date DESC LIMIT 1";
|
||||||
|
insertBlockStateStatementString = "INSERT INTO `" + table + "-state` (replacedState, typeState, id) VALUES(?, ?, ?)";
|
||||||
|
insertBlockChestDataStatementString = "INSERT INTO `" + table + "-chestdata` (item, itemremove, id, itemtype) values (?, ?, ?, ?)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user