1
0
mirror of https://gitlab.com/mangadex-pub/mangadex_at_home.git synced 2024-11-17 00:22:32 +01:00

Don't delete DB entries

This commit is contained in:
carbotaniuman 2020-07-04 10:27:43 -05:00
parent 13c372038e
commit 61e32327d6

View File

@ -163,23 +163,14 @@ class ImageServer(private val cache: DiskLruCache, private val statistics: Atomi
} else { } else {
if (snapshot != null) { if (snapshot != null) {
snapshot.close() snapshot.close()
if (LOGGER.isWarnEnabled) { if (LOGGER.isWarnEnabled) {
LOGGER.warn("Removing cache file for $sanitizedUri without corresponding DB entry") LOGGER.warn("Removing cache file for $sanitizedUri without corresponding DB entry")
} }
cache.removeUnsafe(imageId.toCacheId()) cache.removeUnsafe(imageId.toCacheId())
} }
if (imageDatum != null) {
if (LOGGER.isWarnEnabled) {
LOGGER.warn("Deleting DB entry for $sanitizedUri without corresponding file")
}
synchronized(database) {
transaction(database) {
imageDatum.delete()
}
}
}
request.handleCacheMiss(sanitizedUri, getRc4(rc4Bytes), imageId) request.handleCacheMiss(sanitizedUri, getRc4(rc4Bytes), imageId, imageDatum)
} }
} }
} }
@ -217,7 +208,7 @@ class ImageServer(private val cache: DiskLruCache, private val statistics: Atomi
} }
} }
private fun Request.handleCacheMiss(sanitizedUri: String, cipher: Cipher, imageId: String): Response { private fun Request.handleCacheMiss(sanitizedUri: String, cipher: Cipher, imageId: String, imageDatum: ImageDatum?): Response {
if (LOGGER.isInfoEnabled) { if (LOGGER.isInfoEnabled) {
LOGGER.info("Request for $sanitizedUri missed cache") LOGGER.info("Request for $sanitizedUri missed cache")
} }
@ -252,6 +243,7 @@ class ImageServer(private val cache: DiskLruCache, private val statistics: Atomi
LOGGER.trace("Request for $sanitizedUri is being cached and served") LOGGER.trace("Request for $sanitizedUri is being cached and served")
} }
if(imageDatum == null) {
synchronized(database) { synchronized(database) {
transaction(database) { transaction(database) {
ImageDatum.new(imageId) { ImageDatum.new(imageId) {
@ -260,6 +252,7 @@ class ImageServer(private val cache: DiskLruCache, private val statistics: Atomi
} }
} }
} }
}
val tee = CachingInputStream( val tee = CachingInputStream(
mdResponse.body.stream, mdResponse.body.stream,