forked from mirror/BlueMap
Fix delete statements doing a full table scan
This commit is contained in:
parent
37dd18190b
commit
a6402850c9
@ -113,10 +113,12 @@ public int writeMapTile(
|
||||
|
||||
@Override
|
||||
public int deleteMapTile(String mapId, int lod, int x, int z, Compression compression) throws IOException {
|
||||
int mapKey = mapKey(mapId);
|
||||
int compressionKey = compressionKey(compression);
|
||||
return db.run(connection -> {
|
||||
return executeUpdate(connection,
|
||||
deleteMapTileStatement(),
|
||||
mapId, lod, x, z, compression.getKey().getFormatted()
|
||||
mapKey, lod, x, z, compressionKey
|
||||
);
|
||||
});
|
||||
}
|
||||
@ -156,10 +158,11 @@ public int countAllMapTiles(String mapId) throws IOException {
|
||||
|
||||
@Override
|
||||
public int purgeMapTiles(String mapId, int limit) throws IOException {
|
||||
int mapKey = mapKey(mapId);
|
||||
return db.run(connection -> {
|
||||
return executeUpdate(connection,
|
||||
purgeMapTilesStatement(),
|
||||
mapId, limit
|
||||
mapKey, limit
|
||||
);
|
||||
});
|
||||
}
|
||||
@ -230,10 +233,11 @@ public int writeMapMeta(String mapId, String itemName, byte[] bytes) throws IOEx
|
||||
|
||||
@Override
|
||||
public int deleteMapMeta(String mapId, String itemName) throws IOException {
|
||||
int mapKey = mapKey(mapId);
|
||||
return db.run(connection -> {
|
||||
return executeUpdate(connection,
|
||||
deleteMapMetaStatement(),
|
||||
mapId, itemName
|
||||
mapKey, itemName
|
||||
);
|
||||
});
|
||||
}
|
||||
@ -265,21 +269,22 @@ public boolean hasMapMeta(String mapId, String itemName) throws IOException {
|
||||
@Override
|
||||
public void purgeMap(String mapId) throws IOException {
|
||||
synchronized (mapKeys) {
|
||||
int mapKey = mapKey(mapId);
|
||||
db.run(connection -> {
|
||||
|
||||
executeUpdate(connection,
|
||||
purgeMapTileTableStatement(),
|
||||
mapId
|
||||
mapKey
|
||||
);
|
||||
|
||||
executeUpdate(connection,
|
||||
purgeMapMetaTableStatement(),
|
||||
mapId
|
||||
mapKey
|
||||
);
|
||||
|
||||
executeUpdate(connection,
|
||||
deleteMapStatement(),
|
||||
mapId
|
||||
mapKey
|
||||
);
|
||||
|
||||
});
|
||||
|
@ -147,19 +147,11 @@ public String deleteMapTileStatement() {
|
||||
return """
|
||||
DELETE
|
||||
FROM `bluemap_map_tile`
|
||||
WHERE `map` IN (
|
||||
SELECT m.`id`
|
||||
FROM `bluemap_map` m
|
||||
WHERE m.`map_id` = ?
|
||||
)
|
||||
WHERE `map` = ?
|
||||
AND `lod` = ?
|
||||
AND `x` = ?
|
||||
AND `z` = ?
|
||||
AND `compression` IN (
|
||||
SELECT c.`id`
|
||||
FROM `bluemap_map_tile_compression` c
|
||||
WHERE c.`compression` = ?
|
||||
)
|
||||
AND `compression` = ?
|
||||
""";
|
||||
}
|
||||
|
||||
@ -199,11 +191,7 @@ public String purgeMapTilesStatement() {
|
||||
return """
|
||||
DELETE
|
||||
FROM `bluemap_map_tile`
|
||||
WHERE `map` IN (
|
||||
SELECT `id`
|
||||
FROM `bluemap_map`
|
||||
WHERE `map_id` = ?
|
||||
)
|
||||
WHERE `map` = ?
|
||||
LIMIT ?
|
||||
""";
|
||||
}
|
||||
@ -254,11 +242,7 @@ public String deleteMapMetaStatement() {
|
||||
return """
|
||||
DELETE
|
||||
FROM `bluemap_map_meta`
|
||||
WHERE `map` IN (
|
||||
SELECT `id`
|
||||
FROM `bluemap_map`
|
||||
WHERE `map_id` = ?
|
||||
)
|
||||
WHERE `map` = ?
|
||||
AND `key` = ?
|
||||
""";
|
||||
}
|
||||
@ -282,11 +266,7 @@ public String purgeMapTileTableStatement() {
|
||||
return """
|
||||
DELETE
|
||||
FROM `bluemap_map_tile`
|
||||
WHERE `map` IN (
|
||||
SELECT m.`id`
|
||||
FROM `bluemap_map` m
|
||||
WHERE m.`map_id` = ?
|
||||
)
|
||||
WHERE `map` = ?
|
||||
""";
|
||||
}
|
||||
|
||||
@ -296,11 +276,7 @@ public String purgeMapMetaTableStatement() {
|
||||
return """
|
||||
DELETE
|
||||
FROM `bluemap_map_meta`
|
||||
WHERE `map` IN (
|
||||
SELECT m.`id`
|
||||
FROM `bluemap_map` m
|
||||
WHERE m.`map_id` = ?
|
||||
)
|
||||
WHERE `map` = ?
|
||||
""";
|
||||
}
|
||||
|
||||
@ -310,7 +286,7 @@ public String deleteMapStatement() {
|
||||
return """
|
||||
DELETE
|
||||
FROM `bluemap_map`
|
||||
WHERE `map_id` = ?
|
||||
WHERE `map` = ?
|
||||
""";
|
||||
}
|
||||
|
||||
|
@ -141,19 +141,11 @@ public String deleteMapTileStatement() {
|
||||
return """
|
||||
DELETE
|
||||
FROM bluemap_map_tile
|
||||
WHERE map IN (
|
||||
SELECT m.id
|
||||
FROM bluemap_map m
|
||||
WHERE m.map_id = ?
|
||||
)
|
||||
WHERE map = ?
|
||||
AND lod = ?
|
||||
AND x = ?
|
||||
AND z = ?
|
||||
AND compression IN (
|
||||
SELECT c.id
|
||||
FROM bluemap_map_tile_compression c
|
||||
WHERE c.compression = ?
|
||||
)
|
||||
AND compression = ?
|
||||
""";
|
||||
}
|
||||
|
||||
@ -196,9 +188,7 @@ public String purgeMapTilesStatement() {
|
||||
WHERE CTID IN (
|
||||
SELECT CTID
|
||||
FROM bluemap_map_tile t
|
||||
INNER JOIN bluemap_map m
|
||||
ON t.map = m.id
|
||||
WHERE m.map_id = ?
|
||||
WHERE t.map = ?
|
||||
LIMIT ?
|
||||
)
|
||||
""";
|
||||
@ -253,11 +243,7 @@ public String deleteMapMetaStatement() {
|
||||
return """
|
||||
DELETE
|
||||
FROM bluemap_map_meta
|
||||
WHERE map IN (
|
||||
SELECT id
|
||||
FROM bluemap_map
|
||||
WHERE map_id = ?
|
||||
)
|
||||
WHERE map = ?
|
||||
AND key = ?
|
||||
""";
|
||||
}
|
||||
@ -281,11 +267,7 @@ public String purgeMapTileTableStatement() {
|
||||
return """
|
||||
DELETE
|
||||
FROM bluemap_map_tile
|
||||
WHERE map IN (
|
||||
SELECT m.id
|
||||
FROM bluemap_map m
|
||||
WHERE m.map_id = ?
|
||||
)
|
||||
WHERE map = ?
|
||||
""";
|
||||
}
|
||||
|
||||
@ -295,11 +277,7 @@ public String purgeMapMetaTableStatement() {
|
||||
return """
|
||||
DELETE
|
||||
FROM bluemap_map_meta
|
||||
WHERE map IN (
|
||||
SELECT m.id
|
||||
FROM bluemap_map m
|
||||
WHERE m.map_id = ?
|
||||
)
|
||||
WHERE map = ?
|
||||
""";
|
||||
}
|
||||
|
||||
@ -309,7 +287,7 @@ public String deleteMapStatement() {
|
||||
return """
|
||||
DELETE
|
||||
FROM bluemap_map
|
||||
WHERE map_id = ?
|
||||
WHERE map = ?
|
||||
""";
|
||||
}
|
||||
|
||||
|
@ -143,19 +143,11 @@ public String deleteMapTileStatement() {
|
||||
return """
|
||||
DELETE
|
||||
FROM `bluemap_map_tile`
|
||||
WHERE `map` IN (
|
||||
SELECT m.`id`
|
||||
FROM `bluemap_map` m
|
||||
WHERE m.`map_id` = ?
|
||||
)
|
||||
WHERE `map` = ?
|
||||
AND `lod` = ?
|
||||
AND `x` = ?
|
||||
AND `z` = ?
|
||||
AND `compression` IN (
|
||||
SELECT c.`id`
|
||||
FROM `bluemap_map_tile_compression` c
|
||||
WHERE c.`compression` = ?
|
||||
)
|
||||
AND `compression` = ?
|
||||
""";
|
||||
}
|
||||
|
||||
@ -198,9 +190,7 @@ public String purgeMapTilesStatement() {
|
||||
WHERE ROWID IN (
|
||||
SELECT t.ROWID
|
||||
FROM bluemap_map_tile t
|
||||
INNER JOIN bluemap_map m
|
||||
ON t.map = m.id
|
||||
WHERE m.map_id = ?
|
||||
WHERE t.map = ?
|
||||
LIMIT ?
|
||||
)
|
||||
""";
|
||||
@ -252,11 +242,7 @@ public String deleteMapMetaStatement() {
|
||||
return """
|
||||
DELETE
|
||||
FROM `bluemap_map_meta`
|
||||
WHERE `map` IN (
|
||||
SELECT `id`
|
||||
FROM `bluemap_map`
|
||||
WHERE `map_id` = ?
|
||||
)
|
||||
WHERE `map` = ?
|
||||
AND `key` = ?
|
||||
""";
|
||||
}
|
||||
@ -280,11 +266,7 @@ public String purgeMapTileTableStatement() {
|
||||
return """
|
||||
DELETE
|
||||
FROM `bluemap_map_tile`
|
||||
WHERE `map` IN (
|
||||
SELECT m.`id`
|
||||
FROM `bluemap_map` m
|
||||
WHERE m.`map_id` = ?
|
||||
)
|
||||
WHERE `map` = ?
|
||||
""";
|
||||
}
|
||||
|
||||
@ -294,11 +276,7 @@ public String purgeMapMetaTableStatement() {
|
||||
return """
|
||||
DELETE
|
||||
FROM `bluemap_map_meta`
|
||||
WHERE `map` IN (
|
||||
SELECT m.`id`
|
||||
FROM `bluemap_map` m
|
||||
WHERE m.`map_id` = ?
|
||||
)
|
||||
WHERE `map` = ?
|
||||
""";
|
||||
}
|
||||
|
||||
@ -308,7 +286,7 @@ public String deleteMapStatement() {
|
||||
return """
|
||||
DELETE
|
||||
FROM `bluemap_map`
|
||||
WHERE `map_id` = ?
|
||||
WHERE `map` = ?
|
||||
""";
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user