Added internal caching of table names & table counts

This commit is contained in:
Intelli 2022-02-02 21:19:06 -07:00
parent 67d9f2f832
commit 29d01a158a
6 changed files with 50 additions and 26 deletions

View File

@ -473,7 +473,7 @@ public class CoreProtectAPI extends Queue {
}
if (useLimit) {
result = Lookup.performPartialLookup(statement, null, uuids, restrictUsers, restrictBlocks, excludeBlocks, excludeUsers, actionList, location, argRadius, timePeriod, offset, rowCount, restrictWorld, true);
result = Lookup.performPartialLookup(statement, null, uuids, restrictUsers, restrictBlocks, excludeBlocks, excludeUsers, actionList, location, argRadius, null, timePeriod, offset, rowCount, restrictWorld, true);
}
else {
result = Lookup.performLookup(statement, null, uuids, restrictUsers, restrictBlocks, excludeBlocks, excludeUsers, actionList, location, argRadius, timePeriod, restrictWorld, true);

View File

@ -755,27 +755,33 @@ public class LookupCommand {
location = new Location(Bukkit.getServer().getWorld(Util.getWorldName(finalWid)), finalX, finalY, finalZ);
}
Long[] rowData = new Long[] { 0L, 0L, 0L, 0L };
long rowMax = (long) page * displayResults;
long pageStart = rowMax - displayResults;
int rows = 0;
long rows = 0L;
boolean checkRows = true;
if (typeLookup == 5 && page > 1) {
rows = ConfigHandler.lookupRows.get(player2.getName());
rowData = ConfigHandler.lookupRows.get(player2.getName());
rows = rowData[3];
if (pageStart < rows) {
checkRows = false;
}
}
if (checkRows) {
rows = Lookup.countLookupRows(statement, player2, uuidList, userList, blist, elist, euserlist, finalArgAction, location, radius, stime, restrict_world, true);
ConfigHandler.lookupRows.put(player2.getName(), rows);
rows = Lookup.countLookupRows(statement, player2, uuidList, userList, blist, elist, euserlist, finalArgAction, location, radius, rowData, stime, restrict_world, true);
rowData[3] = rows;
ConfigHandler.lookupRows.put(player2.getName(), rowData);
}
if (finalCount) {
String row_format = NumberFormat.getInstance().format(rows);
Chat.sendMessage(player2, Color.DARK_AQUA + "CoreProtect " + Color.WHITE + "- " + Phrase.build(Phrase.LOOKUP_ROWS_FOUND, row_format, (rows == 1 ? Selector.FIRST : Selector.SECOND)));
}
else if (pageStart < rows) {
List<String[]> lookupList = Lookup.performPartialLookup(statement, player2, uuidList, userList, blist, elist, euserlist, finalArgAction, location, radius, stime, (int) pageStart, displayResults, restrict_world, true);
List<String[]> lookupList = Lookup.performPartialLookup(statement, player2, uuidList, userList, blist, elist, euserlist, finalArgAction, location, radius, rowData, stime, (int) pageStart, displayResults, restrict_world, true);
Chat.sendMessage(player2, Color.WHITE + "----- " + Color.DARK_AQUA + Phrase.build(Phrase.LOOKUP_HEADER, "CoreProtect") + Color.WHITE + " -----");
if (finalArgAction.contains(6) || finalArgAction.contains(7)) { // Chat/command
for (String[] data : lookupList) {

View File

@ -103,7 +103,7 @@ public class ConfigHandler extends Queue {
public static Map<String, List<Integer>> lookupAlist = syncMap();
public static Map<String, Integer[]> lookupRadius = syncMap();
public static Map<String, String> lookupTime = syncMap();
public static Map<String, Integer> lookupRows = syncMap();
public static Map<String, Long[]> lookupRows = syncMap();
public static Map<String, String> uuidCache = syncMap();
public static Map<String, String> uuidCacheReversed = syncMap();
public static Map<String, Integer> playerIdCache = syncMap();

View File

@ -28,7 +28,7 @@ public class ContainerRollback extends Queue {
try {
long startTime = System.currentTimeMillis();
final List<Object[]> lookupList = Lookup.performLookupRaw(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, checkTime, -1, -1, restrictWorld, lookup);
final List<Object[]> lookupList = Lookup.performLookupRaw(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, null, checkTime, -1, -1, restrictWorld, lookup);
if (rollbackType == 1) {
Collections.reverse(lookupList);
}

View File

@ -75,8 +75,8 @@ public class Lookup extends Queue {
return newList;
}
public static int countLookupRows(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, long checkTime, boolean restrictWorld, boolean lookup) {
int rows = 0;
public static long countLookupRows(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, Long[] rowData, long checkTime, boolean restrictWorld, boolean lookup) {
Long rows = 0L;
try {
while (Consumer.isPaused) {
@ -84,9 +84,12 @@ public class Lookup extends Queue {
}
Consumer.isPaused = true;
ResultSet results = rawLookupResultSet(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, checkTime, -1, -1, restrictWorld, lookup, true);
ResultSet results = rawLookupResultSet(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, null, checkTime, -1, -1, restrictWorld, lookup, true);
while (results.next()) {
rows += results.getInt("count");
int resultTable = results.getInt("tbl");
long count = results.getLong("count");
rowData[resultTable] = count;
rows += count;
}
results.close();
}
@ -103,7 +106,7 @@ public class Lookup extends Queue {
List<String[]> newList = new ArrayList<>();
try {
List<Object[]> lookupList = performLookupRaw(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, checkTime, -1, -1, restrictWorld, lookup);
List<Object[]> lookupList = performLookupRaw(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, null, checkTime, -1, -1, restrictWorld, lookup);
newList = convertRawLookup(statement, lookupList);
}
catch (Exception e) {
@ -113,7 +116,7 @@ public class Lookup extends Queue {
return newList;
}
static List<Object[]> performLookupRaw(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, long checkTime, int limitOffset, int limitCount, boolean restrictWorld, boolean lookup) {
static List<Object[]> performLookupRaw(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, Long[] rowData, long checkTime, int limitOffset, int limitCount, boolean restrictWorld, boolean lookup) {
List<Object[]> list = new ArrayList<>();
List<Integer> invalidRollbackActions = new ArrayList<>();
invalidRollbackActions.add(2);
@ -129,7 +132,7 @@ public class Lookup extends Queue {
Consumer.isPaused = true;
ResultSet results = rawLookupResultSet(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, checkTime, limitOffset, limitCount, restrictWorld, lookup, false);
ResultSet results = rawLookupResultSet(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, rowData, checkTime, limitOffset, limitCount, restrictWorld, lookup, false);
while (results.next()) {
if (actionList.contains(6) || actionList.contains(7)) {
@ -256,11 +259,11 @@ public class Lookup extends Queue {
return list;
}
public static List<String[]> performPartialLookup(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, long checkTime, int limitOffset, int limitCount, boolean restrictWorld, boolean lookup) {
public static List<String[]> performPartialLookup(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, Long[] rowData, long checkTime, int limitOffset, int limitCount, boolean restrictWorld, boolean lookup) {
List<String[]> newList = new ArrayList<>();
try {
List<Object[]> lookupList = performLookupRaw(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, checkTime, limitOffset, limitCount, restrictWorld, lookup);
List<Object[]> lookupList = performLookupRaw(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, rowData, checkTime, limitOffset, limitCount, restrictWorld, lookup);
newList = convertRawLookup(statement, lookupList);
}
catch (Exception e) {
@ -270,7 +273,7 @@ public class Lookup extends Queue {
return newList;
}
private static ResultSet rawLookupResultSet(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, long checkTime, int limitOffset, int limitCount, boolean restrictWorld, boolean lookup, boolean count) {
private static ResultSet rawLookupResultSet(Statement statement, CommandSender user, List<String> checkUuids, List<String> checkUsers, List<Object> restrictList, List<Object> excludeList, List<String> excludeUserList, List<Integer> actionList, Location location, Integer[] radius, Long[] rowData, long checkTime, int limitOffset, int limitCount, boolean restrictWorld, boolean lookup, boolean count) {
ResultSet results = null;
try {
@ -284,7 +287,6 @@ public class Lookup extends Queue {
String queryEntity = "";
String queryLimit = "";
String queryTable = "block";
String unionLimit = "";
String action = "";
String includeBlock = "";
String includeEntity = "";
@ -293,6 +295,7 @@ public class Lookup extends Queue {
String users = "";
String uuids = "";
String excludeUsers = "";
String unionLimit = "";
String index = "";
String query = "";
@ -601,8 +604,8 @@ public class Lookup extends Queue {
if (count) {
rows = "COUNT(*) as count";
queryLimit = " LIMIT 0, 3";
unionLimit = "";
queryOrder = "";
unionLimit = "";
}
if (Config.getGlobal().MYSQL) {
@ -655,7 +658,7 @@ public class Lookup extends Queue {
baseQuery = baseQuery.replace("action NOT IN(-1)", "action NOT IN(3)"); // if block specified for include/exclude, filter out entity data
}
query = "(SELECT " + rows + " FROM " + ConfigHandler.prefix + queryTable + " " + index + "WHERE" + baseQuery + unionLimit + ") UNION ALL ";
query = "(SELECT " + (count ? "'0' as tbl," : "") + rows + " FROM " + ConfigHandler.prefix + queryTable + " " + index + "WHERE" + baseQuery + unionLimit + ") UNION ALL ";
itemLookup = true;
}
@ -663,17 +666,17 @@ public class Lookup extends Queue {
if (!count) {
rows = "rowid as id,time,user,wid,x,y,z,type,metadata,data,amount,action,rolled_back";
}
query = query + "(SELECT " + rows + " FROM " + ConfigHandler.prefix + "container " + index + "WHERE" + queryBlock + unionLimit + ") UNION ALL ";
query = query + "(SELECT " + (count ? "'1' as tbl," : "") + rows + " FROM " + ConfigHandler.prefix + "container " + index + "WHERE" + queryBlock + unionLimit + ") UNION ALL ";
if (!count) {
rows = "rowid as id,time,user,wid,x,y,z,type,data as metadata,0 as data,amount,action,0 as rolled_back";
queryOrder = " ORDER BY time DESC, id DESC";
}
query = query + "(SELECT " + rows + " FROM " + ConfigHandler.prefix + "item " + index + "WHERE" + queryBlock + unionLimit + ")";
query = query + "(SELECT " + (count ? "'2' as tbl," : "") + rows + " FROM " + ConfigHandler.prefix + "item " + index + "WHERE" + queryBlock + unionLimit + ")";
}
if (query.length() == 0) {
query = "SELECT " + rows + " FROM " + ConfigHandler.prefix + queryTable + " " + index + "WHERE" + baseQuery;
query = "SELECT " + (count ? "'0' as tbl," : "") + rows + " FROM " + ConfigHandler.prefix + queryTable + " " + index + "WHERE" + baseQuery;
}
query = query + queryOrder + queryLimit + "";
@ -686,6 +689,21 @@ public class Lookup extends Queue {
return results;
}
/*
private static long calculateTableOffset(long col2, long col3, long limitOffset, int limitCount) {
return (limitOffset - (col2 + col3)) < 0L ? 0L : (limitOffset - (col2 + col3));
}
private static long calculateTableLimit(long col1, long col2, long col3, long limitOffset, int limitCount) {
long offset = calculateTableOffset(col2, col3, limitOffset, limitCount);
long limit = (col2 + col3) + limitCount;
limit = (limit > (limitOffset + limitCount)) ? (limitOffset + limitCount) : limit;
limit = (limit > (col1 - offset)) ? (col1 - offset) : limit;
return limit;
}
*/
public static String whoPlaced(Statement statement, BlockState block) {
String result = "";

View File

@ -96,7 +96,7 @@ public class Rollback extends Queue {
List<Object[]> lookupList = new ArrayList<>();
if (!actionList.contains(4) && !actionList.contains(5) && !checkUsers.contains("#container")) {
lookupList = Lookup.performLookupRaw(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, checkTime, -1, -1, restrictWorld, lookup);
lookupList = Lookup.performLookupRaw(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, location, radius, null, checkTime, -1, -1, restrictWorld, lookup);
}
if (lookupList == null) {
@ -130,7 +130,7 @@ public class Rollback extends Queue {
itemActionList.add(4);
}
itemList = Lookup.performLookupRaw(statement, user, checkUuids, checkUsers, itemRestrictList, itemExcludeList, excludeUserList, itemActionList, location, radius, checkTime, -1, -1, restrictWorld, lookup);
itemList = Lookup.performLookupRaw(statement, user, checkUuids, checkUsers, itemRestrictList, itemExcludeList, excludeUserList, itemActionList, location, radius, null, checkTime, -1, -1, restrictWorld, lookup);
}
TreeMap<Long, Integer> chunkList = new TreeMap<>();