Ensure QrCodeInterceptor cache thread-safe

This commit is contained in:
Dude so hot authored and renovate[bot] committed 2024-10-15 13:03:18 +08:00
1 parent 9c6a5af87e
commit e1de57c98c
1 file changed
+1 -1
@@ -33,7 +33,7 @@ object QrCodeInterceptor : Interceptor {
if (image is BitmapImageWithExtraInfo) {
fun compute() = runSuspendCatching { hasQrCode(image.image.bitmap) }.onFailure { logcat(it) }.getOrThrow()
val hasQrCode = when (val key = result.memoryCacheKey) {
is MemoryCache.Key -> cache[key] ?: compute().also { cache[key] = it }
is MemoryCache.Key -> synchronized(cache) { cache[key] } ?: compute().also { synchronized(cache) { cache[key] = it } }
null -> compute()
}
val new = image.copy(hasQrCode = hasQrCode)