From 91113fbc6d9cb9c694b2b766a4fc16246dacd1f8 Mon Sep 17 00:00:00 2001 From: Bryan Montz Date: Mon, 15 May 2023 08:33:35 -0500 Subject: [PATCH] allow models to fetch profiles when they get stale --- damus/Models/FollowingModel.swift | 2 +- damus/Models/SearchHomeModel.swift | 16 +++------------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/damus/Models/FollowingModel.swift b/damus/Models/FollowingModel.swift index 900a2867..4638dd26 100644 --- a/damus/Models/FollowingModel.swift +++ b/damus/Models/FollowingModel.swift @@ -24,7 +24,7 @@ class FollowingModel { var f = NostrFilter.filter_kinds([NostrKind.metadata.rawValue]) f.authors = self.contacts.reduce(into: Array()) { acc, pk in // don't fetch profiles we already have - if damus_state.profiles.lookup(id: pk) != nil { + if damus_state.profiles.has_fresh_profile(id: pk) { return } acc.append(pk) diff --git a/damus/Models/SearchHomeModel.swift b/damus/Models/SearchHomeModel.swift index 3b8c4642..0d6af0cf 100644 --- a/damus/Models/SearchHomeModel.swift +++ b/damus/Models/SearchHomeModel.swift @@ -100,17 +100,7 @@ func find_profiles_to_fetch(profiles: Profiles, load: PubkeysToLoad, cache: Even } func find_profiles_to_fetch_from_keys(profiles: Profiles, pks: [String]) -> [String] { - var pubkeys = Set() - - for pk in pks { - if profiles.lookup(id: pk) != nil { - continue - } - - pubkeys.insert(pk) - } - - return Array(pubkeys) + Array(Set(pks.filter { pk in !profiles.has_fresh_profile(id: pk) })) } func find_profiles_to_fetch_from_events(profiles: Profiles, events: [NostrEvent], cache: EventCache) -> [String] { @@ -118,11 +108,11 @@ func find_profiles_to_fetch_from_events(profiles: Profiles, events: [NostrEvent] for ev in events { // lookup profiles from boosted events - if ev.known_kind == .boost, let bev = ev.get_inner_event(cache: cache), profiles.lookup(id: bev.pubkey) == nil { + if ev.known_kind == .boost, let bev = ev.get_inner_event(cache: cache), !profiles.has_fresh_profile(id: bev.pubkey) { pubkeys.insert(bev.pubkey) } - if profiles.lookup(id: ev.pubkey) == nil { + if !profiles.has_fresh_profile(id: ev.pubkey) { pubkeys.insert(ev.pubkey) } }