Fix insertion of pending chunks using too many parameters

- Fixes #91
pull/95/head
trivernis 4 years ago
parent f0ea063026
commit 65e3e090bb

@ -2,6 +2,7 @@ package net.trivernis.chunkmaster.lib.database
import net.trivernis.chunkmaster.lib.generation.ChunkCoordinates import net.trivernis.chunkmaster.lib.generation.ChunkCoordinates
import java.util.concurrent.CompletableFuture import java.util.concurrent.CompletableFuture
import kotlin.math.ceil
class PendingChunks(private val sqliteManager: SqliteManager) { class PendingChunks(private val sqliteManager: SqliteManager) {
/** /**
@ -30,10 +31,25 @@ class PendingChunks(private val sqliteManager: SqliteManager) {
return completableFuture return completableFuture
} }
fun addPendingChunks(taskId: Int, pendingChunks: List<ChunkCoordinates>): CompletableFuture<Void> {
val futures = ArrayList<CompletableFuture<Void>>()
val statementCount = ceil(pendingChunks.size.toDouble() / 100.0).toInt()
for (i in 0 until statementCount) {
futures.add(insertPendingChunks(taskId, pendingChunks.subList(i * 100, ((i * 100) + 100).coerceAtMost(pendingChunks.size))))
}
if (futures.size > 0) {
return CompletableFuture.allOf(*futures.toTypedArray())
} else {
return CompletableFuture.supplyAsync { null }
}
}
/** /**
* Adds pending chunks for a taskid * Adds pending chunks for a taskid
*/ */
fun addPendingChunks(taskId: Int, pendingChunks: List<ChunkCoordinates>): CompletableFuture<Void> { private fun insertPendingChunks(taskId: Int, pendingChunks: List<ChunkCoordinates>): CompletableFuture<Void> {
val completableFuture = CompletableFuture<Void>() val completableFuture = CompletableFuture<Void>()
if (pendingChunks.isEmpty()) { if (pendingChunks.isEmpty()) {
completableFuture.complete(null) completableFuture.complete(null)

Loading…
Cancel
Save