Don't process blurhash if we already have image cached
Changelog-Fixed: Don't process blurhash if we already have image cached
This commit is contained in:
@@ -385,10 +385,6 @@ func preload_event(plan: PreloadPlan, state: DamusState) async {
|
|||||||
|
|
||||||
print("Preloading event \(plan.event.content)")
|
print("Preloading event \(plan.event.content)")
|
||||||
|
|
||||||
for meta in plan.img_metadata {
|
|
||||||
process_image_metadata(cache: state.events, meta: meta, ev: plan.event)
|
|
||||||
}
|
|
||||||
|
|
||||||
preload_pfp(profiles: profiles, pubkey: plan.event.pubkey)
|
preload_pfp(profiles: profiles, pubkey: plan.event.pubkey)
|
||||||
if let inner_ev = plan.event.get_inner_event(cache: state.events), inner_ev.pubkey != plan.event.pubkey {
|
if let inner_ev = plan.event.get_inner_event(cache: state.events), inner_ev.pubkey != plan.event.pubkey {
|
||||||
preload_pfp(profiles: profiles, pubkey: inner_ev.pubkey)
|
preload_pfp(profiles: profiles, pubkey: inner_ev.pubkey)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import UIKit
|
import UIKit
|
||||||
|
import Kingfisher
|
||||||
|
|
||||||
struct ImageMetaDim: Equatable, StringCodable {
|
struct ImageMetaDim: Equatable, StringCodable {
|
||||||
init(width: Int, height: Int) {
|
init(width: Int, height: Int) {
|
||||||
@@ -191,39 +192,29 @@ func process_image_metadatas(cache: EventCache, ev: NostrEvent) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We don't need blurhash if we already have the source image cached
|
||||||
|
if ImageCache.default.isCached(forKey: meta.url.absoluteString) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
let state = ImageMetadataState(state: meta.blurhash == nil ? .not_needed : .processing, meta: meta)
|
let state = ImageMetadataState(state: meta.blurhash == nil ? .not_needed : .processing, meta: meta)
|
||||||
cache.store_img_metadata(url: meta.url, meta: state)
|
cache.store_img_metadata(url: meta.url, meta: state)
|
||||||
|
|
||||||
guard let blurhash = meta.blurhash else {
|
guard let blurhash = state.meta.blurhash else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
Task {
|
Task {
|
||||||
guard let img = await process_blurhash(blurhash: blurhash, size: meta.dim?.size) else {
|
let img = await process_blurhash(blurhash: blurhash, size: state.meta.dim?.size)
|
||||||
return
|
|
||||||
}
|
|
||||||
Task { @MainActor in
|
Task { @MainActor in
|
||||||
state.state = .processed(img)
|
if let img {
|
||||||
|
state.state = .processed(img)
|
||||||
|
} else {
|
||||||
|
state.state = .failed
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func process_image_metadata(cache: EventCache, meta: ImageMetadata, ev: NostrEvent) {
|
|
||||||
guard let blurhash = meta.blurhash else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
Task {
|
|
||||||
let img = await process_blurhash(blurhash: blurhash, size: meta.dim?.size)
|
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
if let img {
|
|
||||||
let state = ImageMetadataState(state: .processed(img), meta: meta)
|
|
||||||
cache.store_img_metadata(url: meta.url, meta: state)
|
|
||||||
} else {
|
|
||||||
let state = ImageMetadataState(state: .failed, meta: meta)
|
|
||||||
cache.store_img_metadata(url: meta.url, meta: state)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user