Skip to content

Commit

Permalink
update sqlite and use batched inserts
Browse files Browse the repository at this point in the history
  • Loading branch information
rfresh2 committed Dec 5, 2024
1 parent 6d9b736 commit 2a1bfa2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,15 @@ public void insertHighlightList(final List<ChunkHighlightData> chunks, final Res

private void insertHighlightsListInternal(final List<ChunkHighlightData> chunks, final ResourceKey<Level> dimension) {
try {
StringBuilder sb = new StringBuilder("INSERT OR IGNORE INTO \"" + getTableName(dimension) + "\" VALUES ");
for (int i = 0; i < chunks.size(); i++) {
ChunkHighlightData chunk = chunks.get(i);
sb.append("(").append(chunk.x()).append(", ").append(chunk.z()).append(", ").append(chunk.foundTime()).append(")");
if (i < chunks.size() - 1) {
sb.append(", ");
try (var ps = connection.prepareStatement("INSERT OR IGNORE INTO \"" + getTableName(dimension) + "\" VALUES (?, ?, ?)")) {
for (int i = 0; i < chunks.size(); i++) {
final ChunkHighlightData chunk = chunks.get(i);
ps.setInt(1, chunk.x());
ps.setInt(2, chunk.z());
ps.setLong(3, chunk.foundTime());
ps.addBatch();
}
}
try (var stmt = connection.createStatement()) {
stmt.executeUpdate(sb.toString());
ps.executeBatch();
}
} catch (Exception e) {
XaeroPlus.LOGGER.error("Error inserting {} chunks into {} database in dimension: {}", chunks.size(), databaseName, dimension.location(), e);
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dependencyResolutionManagement {
library("balm-forge", "maven.modrinth:balm:7.3.6+forge-1.20.1")
library("fabric-waystones", "maven.modrinth:fwaystones:3.3.2+mc1.20.1")
library("worldtools", "maven.modrinth:worldtools:1.2.4+1.20.1")
library("sqlite", "org.rfresh.xerial:sqlite-jdbc:3.46.1.0") // relocated xerial sqlite to avoid conflicts with other mods
library("sqlite", "org.rfresh.xerial:sqlite-jdbc:3.47.1.0") // relocated xerial sqlite to avoid conflicts with other mods
library("immediatelyfast", "maven.modrinth:immediatelyfast:1.2.18+1.20.4-fabric")
library("modmenu", "maven.modrinth:modmenu:7.2.2")
library("sodium", "maven.modrinth:sodium:mc1.20.1-0.5.11")
Expand Down

0 comments on commit 2a1bfa2

Please sign in to comment.