Fix offset/limit on enums

This commit is contained in:
Mike Primm 2022-07-24 14:56:25 -05:00
parent c80f7adb23
commit 8beba92f8e
5 changed files with 51 additions and 36 deletions

View File

@ -311,32 +311,6 @@ public class MapManager {
rendertype = RENDERTYPE_FULLRENDER;
}
this.resume = resume;
final CountDownLatch latch = new CountDownLatch(1);
if (resume) { // if resume render
final MapStorage ms = world.getMapStorage();
ms.enumMapBaseTiles(world, map, new MapStorageBaseTileEnumCB() {
@Override
public void tileFound(MapStorageTile tile, MapType.ImageEncoding enc) {
String tileId = String.format("%s_%s_%d_%d", tile.world.getName(), tile.map.getName(), tile.x, tile.y);
//sender.sendMessage("Tile found: " + tileId);
storedTileIds.add(tileId);
}
}, new MapStorageTileSearchEndCB() {
@Override
public void searchEnded() {
latch.countDown();
}
});
try {
latch.await(10, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
sender.sendMessage(e.toString());
}
}
}
/* Full world, all maps render, with optional render radius */
@ -528,6 +502,27 @@ public class MapManager {
}
return;
}
// If doing resume, load existing tile IDs here (constructor was stupid, and caused timeouts for non-trivial maps - need to check PRs better....
if (resume) { // if resume render
sendMessage(String.format("Scanning map to find existing tiles for resume..."));
final MapStorage ms = world.getMapStorage();
ms.enumMapBaseTiles(world, map, new MapStorageBaseTileEnumCB() {
@Override
public void tileFound(MapStorageTile tile, MapType.ImageEncoding enc) {
String tileId = String.format("%s_%s_%d_%d", tile.world.getName(), tile.map.getName(), tile.x, tile.y);
//sender.sendMessage("Tile found: " + tileId);
storedTileIds.add(tileId);
}
}, new MapStorageTileSearchEndCB() {
@Override
public void searchEnded() {
}
});
sendMessage(String.format("Scan complete - starting render"));
resume = false; // Only due on first run
}
if(tile0 == null) { /* Not single tile render */
if (saverestorepending && world.isLoaded() && (savependingperiod > 0) && ((lastPendingSaveTS + (1000 *savependingperiod)) < System.currentTimeMillis())) {
savePending(this.world, true); // Save the pending data for the given world

View File

@ -673,11 +673,13 @@ public class MicrosoftSQLMapStorage extends MapStorage {
try {
c = getConnection();
boolean done = false;
int offset = 0;
int limit = 100;
while (!done) {
// Query tiles for given mapkey
Statement stmt = c.createStatement();
ResultSet rs = stmt.executeQuery("SELECT x,y,zoom,Format FROM " + tableTiles + " WHERE MapID=" + mapkey + " LIMIT 100;");
ResultSet rs = stmt.executeQuery(String.format("SELECT x,y,zoom,Format FROM %s WHERE MapID=%d OFFSET %d LIMIT %d;", tableTiles, mapkey, offset, limit));
int cnt = 0;
while (rs.next()) {
StorageTile st = new StorageTile(world, map, rs.getInt("x"), rs.getInt("y"), rs.getInt("zoom"), var);
@ -691,7 +693,8 @@ public class MicrosoftSQLMapStorage extends MapStorage {
}
rs.close();
stmt.close();
if (cnt < 100) done = true;
if (cnt < limit) done = true;
offset += cnt;
}
if(cbEnd != null)
cbEnd.searchEnded();

View File

@ -793,10 +793,12 @@ public class MySQLMapStorage extends MapStorage {
try {
c = getConnection();
boolean done = false;
int limit = 100;
int offset = 0;
while (!done) {
// Query tiles for given mapkey
Statement stmt = c.createStatement();
ResultSet rs = stmt.executeQuery("SELECT x,y,zoom,Format FROM " + tableTiles + " WHERE MapID=" + mapkey + " LIMIT 100;");
ResultSet rs = stmt.executeQuery(String.format("SELECT x,y,zoom,Format FROM %s WHERE MapID=%d OFFSET %d LIMIT %d;", tableTiles, mapkey, offset, limit));
int cnt = 0;
while (rs.next()) {
StorageTile st = new StorageTile(world, map, rs.getInt("x"), rs.getInt("y"), rs.getInt("zoom"), var);
@ -810,7 +812,8 @@ public class MySQLMapStorage extends MapStorage {
}
rs.close();
stmt.close();
if (cnt < 100) done = true;
if (cnt < limit) done = true;
offset += cnt;
}
if(cbEnd != null)
cbEnd.searchEnded();

View File

@ -699,11 +699,12 @@ public class PostgreSQLMapStorage extends MapStorage {
try {
c = getConnection();
boolean done = false;
int offset = 0;
int limit = 100;
while (!done) {
// Query tiles for given mapkey
Statement stmt = c.createStatement();
ResultSet rs = stmt.executeQuery("SELECT x,y,zoom,Format FROM " + tableTiles + " WHERE MapID=" + mapkey + " LIMIT 100;");
ResultSet rs = stmt.executeQuery(String.format("SELECT x,y,zoom,Format FROM %s WHERE MapID=%d OFFSET %d LIMIT %d;", tableTiles, mapKey, offset, limit));
int cnt = 0;
while (rs.next()) {
StorageTile st = new StorageTile(world, map, rs.getInt("x"), rs.getInt("y"), rs.getInt("zoom"), var);
@ -717,7 +718,8 @@ public class PostgreSQLMapStorage extends MapStorage {
}
rs.close();
stmt.close();
if (cnt < 100) done = true;
if (cnt < limit) done = true;
offset += cnt;
}
if(cbEnd != null)
cbEnd.searchEnded();

View File

@ -640,12 +640,14 @@ public class SQLiteMapStorage extends MapStorage {
return;
}
try {
c = getConnection();
boolean done = false;
int offset = 0;
int limit = 100;
while (!done) {
c = getConnection(); // Do inside loop - single threaded sqlite will have issues otherwise....
// Query tiles for given mapkey
Statement stmt = c.createStatement();
ResultSet rs = doExecuteQuery(stmt, "SELECT x,y,zoom,Format FROM Tiles WHERE MapID=" + mapkey + " LIMIT 100;");
ResultSet rs = doExecuteQuery(stmt, String.format("SELECT x,y,zoom,Format FROM Tiles WHERE MapID=%d OFFSET %d LIMIT %d", mapkey, offset, limit));
int cnt = 0;
while (rs.next()) {
StorageTile st = new StorageTile(world, map, rs.getInt("x"), rs.getInt("y"), rs.getInt("zoom"), var);
@ -659,7 +661,10 @@ public class SQLiteMapStorage extends MapStorage {
}
rs.close();
stmt.close();
if (cnt < 100) done = true;
if (cnt < limit) done = true;
offset += cnt;
releaseConnection(c, err);
c = null;
}
if(cbEnd != null)
cbEnd.searchEnded();
@ -1055,4 +1060,11 @@ public class SQLiteMapStorage extends MapStorage {
}
}
}
public void logSQLException(String opmsg, SQLException x) {
// Ignore interrupted
if (x.getMessage().equals("Interrupted")) return;
super.logSQLException(opmsg, x);
}
}