Properly synchronised sqlite3 handler across threads
This commit is contained in:
parent
5b78da589e
commit
0afa1d2eaa
|
@ -30,8 +30,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- [2020-06-14] Removed old cache subdirectory migration system by [@carbotaniuman].
|
||||
|
||||
### Fixed
|
||||
- [2020-06-15] Fixed tokenized data-saver parser not working by [@lflare].
|
||||
- [2020-06-14] Switched cache metadata over to a MySql instance [@carbotaniuman].
|
||||
- [2020-06-15] Fixed tokenized data-saver parser not working by [@lflare].
|
||||
- [2020-06-15] Properly synchronised sqlite3 handler across threads by [@lflare].
|
||||
|
||||
## [1.0.0-RC16] - 2020-06-14
|
||||
### Added
|
||||
|
|
|
@ -77,9 +77,11 @@ class ImageServer(private val cache: DiskLruCache, private val statistics: Atomi
|
|||
val imageId = printHexString(rc4Bytes)
|
||||
|
||||
val snapshot = cache.getUnsafe(imageId.toCacheId())
|
||||
val imageDatum = transaction(database) {
|
||||
val imageDatum = synchronized(database) {
|
||||
transaction(database) {
|
||||
ImageDatum.findById(imageId)
|
||||
}
|
||||
}
|
||||
|
||||
if (snapshot != null && imageDatum != null) {
|
||||
request.handleCacheHit(sanitizedUri, getRc4(rc4Bytes), snapshot, imageDatum)
|
||||
|
@ -96,10 +98,12 @@ class ImageServer(private val cache: DiskLruCache, private val statistics: Atomi
|
|||
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)
|
||||
.header("X-Uri", sanitizedUri)
|
||||
|
@ -174,12 +178,14 @@ 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val tee = CachingInputStream(
|
||||
mdResponse.body.stream,
|
||||
|
|
Loading…
Reference in a new issue