fix: remove caching of ZipFile

closes #801
This commit is contained in:
Gauthier Roebroeck 2022-02-14 10:45:51 +08:00
parent c0c7b09faa
commit 57082bd990

View file

@ -1,6 +1,5 @@
package org.gotson.komga.infrastructure.mediacontainer
import com.github.benmanes.caffeine.cache.Caffeine
import mu.KotlinLogging
import net.greypanther.natsort.CaseInsensitiveSimpleNaturalComparator
import org.apache.commons.compress.archivers.ArchiveEntry
@ -10,7 +9,6 @@ import org.gotson.komga.domain.model.MediaType
import org.gotson.komga.infrastructure.image.ImageAnalyzer
import org.springframework.stereotype.Service
import java.nio.file.Path
import java.util.concurrent.TimeUnit
private val logger = KotlinLogging.logger {}
@ -20,12 +18,6 @@ class ZipExtractor(
private val imageAnalyzer: ImageAnalyzer,
) : MediaContainerExtractor {
private val cache = Caffeine.newBuilder()
.maximumSize(20)
.expireAfterAccess(1, TimeUnit.MINUTES)
.evictionListener { _: Path?, zip: ZipFile?, _ -> zip?.close() }
.build<Path, ZipFile>()
private val natSortComparator: Comparator<String> = CaseInsensitiveSimpleNaturalComparator.getInstance()
override fun mediaTypes(): List<String> = listOf(MediaType.ZIP.value)
@ -53,8 +45,8 @@ class ZipExtractor(
.sortedWith(compareBy(natSortComparator) { it.name })
}
override fun getEntryStream(path: Path, entryName: String): ByteArray {
val zip = cache.get(path) { ZipFile(path.toFile()) }!!
return zip.getInputStream(zip.getEntry(entryName)).use { it.readBytes() }
}
override fun getEntryStream(path: Path, entryName: String): ByteArray =
ZipFile(path.toFile()).use { zip ->
zip.getInputStream(zip.getEntry(entryName)).use { it.readBytes() }
}
}