mirror of
https://github.com/PlayPro/CoreProtect.git
synced 2024-11-25 12:25:37 +01:00
Added internal caching of table names & table counts
This commit is contained in:
parent
67d9f2f832
commit
29d01a158a
@ -473,7 +473,7 @@ public class CoreProtectAPI extends Queue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (useLimit) {
|
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 {
|
else {
|
||||||
result = Lookup.performLookup(statement, null, uuids, restrictUsers, restrictBlocks, excludeBlocks, excludeUsers, actionList, location, argRadius, timePeriod, restrictWorld, true);
|
result = Lookup.performLookup(statement, null, uuids, restrictUsers, restrictBlocks, excludeBlocks, excludeUsers, actionList, location, argRadius, timePeriod, restrictWorld, true);
|
||||||
|
@ -755,27 +755,33 @@ public class LookupCommand {
|
|||||||
location = new Location(Bukkit.getServer().getWorld(Util.getWorldName(finalWid)), finalX, finalY, finalZ);
|
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 rowMax = (long) page * displayResults;
|
||||||
long pageStart = rowMax - displayResults;
|
long pageStart = rowMax - displayResults;
|
||||||
int rows = 0;
|
long rows = 0L;
|
||||||
boolean checkRows = true;
|
boolean checkRows = true;
|
||||||
|
|
||||||
if (typeLookup == 5 && page > 1) {
|
if (typeLookup == 5 && page > 1) {
|
||||||
rows = ConfigHandler.lookupRows.get(player2.getName());
|
rowData = ConfigHandler.lookupRows.get(player2.getName());
|
||||||
|
rows = rowData[3];
|
||||||
|
|
||||||
if (pageStart < rows) {
|
if (pageStart < rows) {
|
||||||
checkRows = false;
|
checkRows = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkRows) {
|
if (checkRows) {
|
||||||
rows = Lookup.countLookupRows(statement, player2, uuidList, userList, blist, elist, euserlist, finalArgAction, location, radius, stime, restrict_world, true);
|
rows = Lookup.countLookupRows(statement, player2, uuidList, userList, blist, elist, euserlist, finalArgAction, location, radius, rowData, stime, restrict_world, true);
|
||||||
ConfigHandler.lookupRows.put(player2.getName(), rows);
|
rowData[3] = rows;
|
||||||
|
ConfigHandler.lookupRows.put(player2.getName(), rowData);
|
||||||
}
|
}
|
||||||
if (finalCount) {
|
if (finalCount) {
|
||||||
String row_format = NumberFormat.getInstance().format(rows);
|
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)));
|
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) {
|
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 + " -----");
|
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
|
if (finalArgAction.contains(6) || finalArgAction.contains(7)) { // Chat/command
|
||||||
for (String[] data : lookupList) {
|
for (String[] data : lookupList) {
|
||||||
|
@ -103,7 +103,7 @@ public class ConfigHandler extends Queue {
|
|||||||
public static Map<String, List<Integer>> lookupAlist = syncMap();
|
public static Map<String, List<Integer>> lookupAlist = syncMap();
|
||||||
public static Map<String, Integer[]> lookupRadius = syncMap();
|
public static Map<String, Integer[]> lookupRadius = syncMap();
|
||||||
public static Map<String, String> lookupTime = 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> uuidCache = syncMap();
|
||||||
public static Map<String, String> uuidCacheReversed = syncMap();
|
public static Map<String, String> uuidCacheReversed = syncMap();
|
||||||
public static Map<String, Integer> playerIdCache = syncMap();
|
public static Map<String, Integer> playerIdCache = syncMap();
|
||||||
|
@ -28,7 +28,7 @@ public class ContainerRollback extends Queue {
|
|||||||
try {
|
try {
|
||||||
long startTime = System.currentTimeMillis();
|
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) {
|
if (rollbackType == 1) {
|
||||||
Collections.reverse(lookupList);
|
Collections.reverse(lookupList);
|
||||||
}
|
}
|
||||||
|
@ -75,8 +75,8 @@ public class Lookup extends Queue {
|
|||||||
return newList;
|
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) {
|
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) {
|
||||||
int rows = 0;
|
Long rows = 0L;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while (Consumer.isPaused) {
|
while (Consumer.isPaused) {
|
||||||
@ -84,9 +84,12 @@ public class Lookup extends Queue {
|
|||||||
}
|
}
|
||||||
Consumer.isPaused = true;
|
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()) {
|
while (results.next()) {
|
||||||
rows += results.getInt("count");
|
int resultTable = results.getInt("tbl");
|
||||||
|
long count = results.getLong("count");
|
||||||
|
rowData[resultTable] = count;
|
||||||
|
rows += count;
|
||||||
}
|
}
|
||||||
results.close();
|
results.close();
|
||||||
}
|
}
|
||||||
@ -103,7 +106,7 @@ public class Lookup extends Queue {
|
|||||||
List<String[]> newList = new ArrayList<>();
|
List<String[]> newList = new ArrayList<>();
|
||||||
|
|
||||||
try {
|
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);
|
newList = convertRawLookup(statement, lookupList);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
@ -113,7 +116,7 @@ public class Lookup extends Queue {
|
|||||||
return newList;
|
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<Object[]> list = new ArrayList<>();
|
||||||
List<Integer> invalidRollbackActions = new ArrayList<>();
|
List<Integer> invalidRollbackActions = new ArrayList<>();
|
||||||
invalidRollbackActions.add(2);
|
invalidRollbackActions.add(2);
|
||||||
@ -129,7 +132,7 @@ public class Lookup extends Queue {
|
|||||||
|
|
||||||
Consumer.isPaused = true;
|
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()) {
|
while (results.next()) {
|
||||||
if (actionList.contains(6) || actionList.contains(7)) {
|
if (actionList.contains(6) || actionList.contains(7)) {
|
||||||
@ -256,11 +259,11 @@ public class Lookup extends Queue {
|
|||||||
return list;
|
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<>();
|
List<String[]> newList = new ArrayList<>();
|
||||||
|
|
||||||
try {
|
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);
|
newList = convertRawLookup(statement, lookupList);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
@ -270,7 +273,7 @@ public class Lookup extends Queue {
|
|||||||
return newList;
|
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;
|
ResultSet results = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -284,7 +287,6 @@ public class Lookup extends Queue {
|
|||||||
String queryEntity = "";
|
String queryEntity = "";
|
||||||
String queryLimit = "";
|
String queryLimit = "";
|
||||||
String queryTable = "block";
|
String queryTable = "block";
|
||||||
String unionLimit = "";
|
|
||||||
String action = "";
|
String action = "";
|
||||||
String includeBlock = "";
|
String includeBlock = "";
|
||||||
String includeEntity = "";
|
String includeEntity = "";
|
||||||
@ -293,6 +295,7 @@ public class Lookup extends Queue {
|
|||||||
String users = "";
|
String users = "";
|
||||||
String uuids = "";
|
String uuids = "";
|
||||||
String excludeUsers = "";
|
String excludeUsers = "";
|
||||||
|
String unionLimit = "";
|
||||||
String index = "";
|
String index = "";
|
||||||
String query = "";
|
String query = "";
|
||||||
|
|
||||||
@ -601,8 +604,8 @@ public class Lookup extends Queue {
|
|||||||
if (count) {
|
if (count) {
|
||||||
rows = "COUNT(*) as count";
|
rows = "COUNT(*) as count";
|
||||||
queryLimit = " LIMIT 0, 3";
|
queryLimit = " LIMIT 0, 3";
|
||||||
unionLimit = "";
|
|
||||||
queryOrder = "";
|
queryOrder = "";
|
||||||
|
unionLimit = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Config.getGlobal().MYSQL) {
|
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
|
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;
|
itemLookup = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -663,17 +666,17 @@ public class Lookup extends Queue {
|
|||||||
if (!count) {
|
if (!count) {
|
||||||
rows = "rowid as id,time,user,wid,x,y,z,type,metadata,data,amount,action,rolled_back";
|
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) {
|
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";
|
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";
|
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) {
|
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 + "";
|
query = query + queryOrder + queryLimit + "";
|
||||||
@ -686,6 +689,21 @@ public class Lookup extends Queue {
|
|||||||
return results;
|
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) {
|
public static String whoPlaced(Statement statement, BlockState block) {
|
||||||
String result = "";
|
String result = "";
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ public class Rollback extends Queue {
|
|||||||
List<Object[]> lookupList = new ArrayList<>();
|
List<Object[]> lookupList = new ArrayList<>();
|
||||||
|
|
||||||
if (!actionList.contains(4) && !actionList.contains(5) && !checkUsers.contains("#container")) {
|
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) {
|
if (lookupList == null) {
|
||||||
@ -130,7 +130,7 @@ public class Rollback extends Queue {
|
|||||||
itemActionList.add(4);
|
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<>();
|
TreeMap<Long, Integer> chunkList = new TreeMap<>();
|
||||||
|
Loading…
Reference in New Issue
Block a user