fix: scan could fail because of sql statement too long

closes #650
This commit is contained in:
Gauthier Roebroeck 2021-09-02 09:18:15 +08:00
parent 6e106f1da7
commit 19204df1c7

View file

@ -7,6 +7,7 @@ import org.gotson.komga.jooq.Tables
import org.gotson.komga.jooq.tables.records.SidecarRecord
import org.jooq.DSLContext
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import java.net.URL
@Component
@ -15,6 +16,7 @@ class SidecarDao(
) : SidecarRepository {
private val sc = Tables.SIDECAR
private val u = Tables.TEMP_URL_LIST
override fun findAll(): Collection<SidecarStored> =
dsl.selectFrom(sc).fetch().map { it.toDomain() }
@ -34,10 +36,24 @@ class SidecarDao(
.execute()
}
@Transactional
override fun deleteByLibraryIdAndUrls(libraryId: String, urls: Collection<URL>) {
// insert urls in a temporary table, else the select size can exceed the statement limit
dsl.deleteFrom(u).execute()
if (urls.isNotEmpty()) {
dsl.batch(
dsl.insertInto(u, u.URL).values(null as String?)
).also { step ->
urls.forEach {
step.bind(it.toString())
}
}.execute()
}
dsl.deleteFrom(sc)
.where(sc.LIBRARY_ID.eq(libraryId))
.and(sc.URL.`in`(urls.map { it.toString() }))
.and(sc.URL.`in`(dsl.select(u.URL).from(u)))
.execute()
}