pfp: profile pic image cache

So we don't have to download 60MB of profile pics every time we load the
app..

Changelog-Added: Added profile picture cache
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2022-08-06 19:22:54 -07:00
parent 7da7bcdfd5
commit 366e3565d1
3 changed files with 114 additions and 49 deletions

View File

@@ -509,7 +509,8 @@ func process_metadata_event(image_cache: ImageCache, profiles: Profiles, ev: Nos
let picture = tprof.profile.picture ?? robohash(ev.pubkey)
if let url = URL(string: picture) {
Task<UIImage?, Never>.init(priority: .background) {
let res = await load_image(cache: image_cache, from: url)
let pfp_key = pfp_cache_key(url: url)
let res = await image_cache.lookup_or_load_image(key: pfp_key, url: url)
DispatchQueue.main.async {
notify(.profile_updated, ProfileUpdate(pubkey: ev.pubkey, profile: profile))
}