From 61e32327d6d21583b2c74fcb94c8aa6ef313600c Mon Sep 17 00:00:00 2001 From: carbotaniuman <41451839+carbotaniuman@users.noreply.github.com> Date: Sat, 4 Jul 2020 10:27:43 -0500 Subject: [PATCH] Don't delete DB entries --- .../kotlin/mdnet/base/server/ImageServer.kt | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/main/kotlin/mdnet/base/server/ImageServer.kt b/src/main/kotlin/mdnet/base/server/ImageServer.kt index adccfbb..4dfd8f3 100644 --- a/src/main/kotlin/mdnet/base/server/ImageServer.kt +++ b/src/main/kotlin/mdnet/base/server/ImageServer.kt @@ -163,23 +163,14 @@ class ImageServer(private val cache: DiskLruCache, private val statistics: Atomi } else { if (snapshot != null) { snapshot.close() + if (LOGGER.isWarnEnabled) { LOGGER.warn("Removing cache file for $sanitizedUri without corresponding DB entry") } 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) { LOGGER.info("Request for $sanitizedUri missed cache") } @@ -252,11 +243,13 @@ class ImageServer(private val cache: DiskLruCache, private val statistics: Atomi LOGGER.trace("Request for $sanitizedUri is being cached and served") } - synchronized(database) { - transaction(database) { - ImageDatum.new(imageId) { - this.contentType = contentType - this.lastModified = lastModified + if(imageDatum == null) { + synchronized(database) { + transaction(database) { + ImageDatum.new(imageId) { + this.contentType = contentType + this.lastModified = lastModified + } } } }