Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ else if (pageStart < rows) {
List<String[]> lookupList = lookupPage == null
? Lookup.performPartialLookup(statement, player, uuidList, userList, blockList, excludedBlocks, excludedUsers, actions, entityActionFilter, messageFilters, entityContext, finalLocation, radius, rowData, timeStart, timeEnd, (int) pageStart, displayResults, restrict_world, true, entityContainerId, rollbackState)
: lookupPage.getRows();
if (lookupList == null) {
return;
}

Map<Integer, EntitySpawnRecord> entitySpawnRecords = Collections.emptyMap();
Map<UUID, Location> loadedEntityLocations = Collections.emptyMap();
Expand Down
45 changes: 43 additions & 2 deletions src/main/java/net/coreprotect/database/LookupRaw.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,25 @@ private static List<Object[]> performLookupRaw(Statement statement, CommandSende
paused = true;
}

if (ConfigHandler.databaseType.isClickHouse() && pageRows == null && limitOffset >= 0 && limitCount > 0) {
pageRows = new HashMap<>();
try (ResultSet pageResults = rawLookupResultSet(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, entityActionFilter, messageFilters, entityContext, location, radius, rowData, startTime, endTime, limitOffset, limitCount, restrictWorld, lookup, false, entityContainerId, false, false, false, rollbackState, null, true)) {
if (pageResults == null) {
return null;
}
while (pageResults.next()) {
int source = pageResults.getInt("tbl");
long rowId = pageResults.getLong("id");
pageRows.computeIfAbsent(source, ignored -> new ArrayList<>()).add(rowId);
}
}
if (pageRows.isEmpty()) {
return list;
}
limitOffset = -1;
limitCount = -1;
}

ResultSet results = rawLookupResultSet(statement, user, checkUuids, checkUsers, restrictList, excludeList, excludeUserList, actionList, entityActionFilter, messageFilters, entityContext, location, radius, rowData, startTime, endTime, limitOffset, limitCount, restrictWorld, lookup, false, entityContainerId, false, false, false, rollbackState, pageRows, false);
if (results == null) {
return null;
Expand Down Expand Up @@ -1148,13 +1167,23 @@ else if (actionList.contains(LookupActions.SIGN)) {
}

if (selectPageRows) {
query = buildDuckDBPageQuery(query, entityLocationCte, pageOffset, limitCount, knownTotalRows, cursor, queryOrder.contains("time DESC"));
if (ConfigHandler.databaseType.isClickHouse()) {
query = buildClickHousePageQuery(query, queryOrder, limitOffset, limitCount);
}
else {
query = buildDuckDBPageQuery(query, entityLocationCte, pageOffset, limitCount, knownTotalRows, cursor, queryOrder.contains("time DESC"));
}
}
else if (summary) {
query = buildSummaryQuery(query, inventoryQuery, countGroups, includeGroupCount, limitOffset, limitCount);
}
else {
query = query + queryOrder + queryLimit + "";
if (ConfigHandler.databaseType.isClickHouse() && query.contains(" UNION ALL ")) {
query = "SELECT * FROM (" + query + ") AS coreprotectLookupUnion" + queryOrder + queryLimit;
}
else {
query = query + queryOrder + queryLimit;
}
}
if (!selectPageRows && !entityLocationCte.isEmpty()) {
query = "WITH " + entityLocationCte + " " + query;
Expand Down Expand Up @@ -1339,6 +1368,18 @@ private static String buildDuckDBPageQuery(String sourceQuery, String entityLoca
return query.toString();
}

private static String buildClickHousePageQuery(String sourceQuery, String queryOrder, int offset, int limit) {
if (limit <= 0) {
throw new IllegalArgumentException("ClickHouse lookup page size must be positive");
}
if (offset < 0) {
throw new IllegalArgumentException("ClickHouse lookup page offset must not be negative");
}
String candidateOrder = queryOrder.replace("rowid", "id");
return "SELECT tbl,id FROM (" + sourceQuery + ") AS coreprotectLookupCandidates"
+ candidateOrder + " LIMIT " + limit + " OFFSET " + offset;
}

private static String buildRollbackPredicate(LookupRollbackState rollbackState, boolean inventoryRollback) {
if (rollbackState == null || rollbackState == LookupRollbackState.ANY) {
return "";
Expand Down