mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-04 10:33:45 +00:00
Prevent images cached on disk from loading on the main queue
This commit is contained in:
@@ -54,18 +54,12 @@ struct MediaProvider: MediaProviderProtocol {
|
|||||||
loadImageBgTask?.stop()
|
loadImageBgTask?.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
let cachedImageLoadResult = await withCheckedContinuation { continuation in
|
|
||||||
imageCache.retrieveImage(forKey: source.underlyingSource.url()) { result in
|
|
||||||
continuation.resume(returning: result)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if case let .success(cacheResult) = cachedImageLoadResult,
|
|
||||||
let image = cacheResult.image {
|
|
||||||
return .success(image)
|
|
||||||
}
|
|
||||||
|
|
||||||
return await Task.detached { () -> Result<UIImage, MediaProviderError> in
|
return await Task.detached { () -> Result<UIImage, MediaProviderError> in
|
||||||
|
if case let .success(cacheResult) = await imageCache.retrieveImage(forKey: source.underlyingSource.url()),
|
||||||
|
let image = cacheResult.image {
|
||||||
|
return .success(image)
|
||||||
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
let imageData = try clientProxy.loadMediaContentForSource(source.underlyingSource)
|
let imageData = try clientProxy.loadMediaContentForSource(source.underlyingSource)
|
||||||
|
|
||||||
@@ -85,3 +79,13 @@ struct MediaProvider: MediaProviderProtocol {
|
|||||||
.value
|
.value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private extension ImageCache {
|
||||||
|
func retrieveImage(forKey key: String) async -> Result<ImageCacheResult, KingfisherError> {
|
||||||
|
await withCheckedContinuation { continuation in
|
||||||
|
retrieveImage(forKey: key) { result in
|
||||||
|
continuation.resume(returning: result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user