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,11 +243,13 @@ 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")
} }
synchronized(database) { if(imageDatum == null) {
transaction(database) { synchronized(database) {
ImageDatum.new(imageId) { transaction(database) {
this.contentType = contentType ImageDatum.new(imageId) {
this.lastModified = lastModified this.contentType = contentType
this.lastModified = lastModified
}
} }
} }
} }