From c80d9c27d548a84c27db19e627253eaccdd5b25f Mon Sep 17 00:00:00 2001 From: William Casarin Date: Mon, 23 Oct 2023 11:21:37 +0800 Subject: [PATCH] load_profiles: add context for debugging This is useful to see where the load_profiles request is coming from We may need to switch to a central dispatch for profile loading, I suspect there is a lot of redundancy between requests. --- damus/Models/EventsModel.swift | 2 +- damus/Models/HomeModel.swift | 6 +++--- damus/Models/ProfileModel.swift | 2 +- damus/Models/SearchHomeModel.swift | 8 ++++---- damus/Models/SearchModel.swift | 2 +- damus/Models/ThreadModel.swift | 2 +- damus/Models/ZapsModel.swift | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/damus/Models/EventsModel.swift b/damus/Models/EventsModel.swift index 7c045e916d..25a61badb6 100644 --- a/damus/Models/EventsModel.swift +++ b/damus/Models/EventsModel.swift @@ -65,7 +65,7 @@ class EventsModel: ObservableObject { break case .eose: let txn = NdbTxn(ndb: self.state.ndb) - load_profiles(profiles_subid: profiles_id, relay_id: relay_id, load: .from_events(events), damus_state: state, txn: txn) + load_profiles(context: "events_model", profiles_subid: profiles_id, relay_id: relay_id, load: .from_events(events), damus_state: state, txn: txn) } } } diff --git a/damus/Models/HomeModel.swift b/damus/Models/HomeModel.swift index fd0a16b6c8..266e853bf3 100644 --- a/damus/Models/HomeModel.swift +++ b/damus/Models/HomeModel.swift @@ -434,11 +434,11 @@ class HomeModel { if sub_id == dms_subid { var dms = dms.dms.flatMap { $0.events } dms.append(contentsOf: incoming_dms) - load_profiles(profiles_subid: profiles_subid, relay_id: relay_id, load: .from_events(dms), damus_state: damus_state, txn: txn) + load_profiles(context: "dms", profiles_subid: profiles_subid, relay_id: relay_id, load: .from_events(dms), damus_state: damus_state, txn: txn) } else if sub_id == notifications_subid { - load_profiles(profiles_subid: profiles_subid, relay_id: relay_id, load: .from_keys(notifications.uniq_pubkeys()), damus_state: damus_state, txn: txn) + load_profiles(context: "notifications", profiles_subid: profiles_subid, relay_id: relay_id, load: .from_keys(notifications.uniq_pubkeys()), damus_state: damus_state, txn: txn) } else if sub_id == home_subid { - load_profiles(profiles_subid: profiles_subid, relay_id: relay_id, load: .from_events(events.events), damus_state: damus_state, txn: txn) + load_profiles(context: "home", profiles_subid: profiles_subid, relay_id: relay_id, load: .from_events(events.events), damus_state: damus_state, txn: txn) } self.loading = false diff --git a/damus/Models/ProfileModel.swift b/damus/Models/ProfileModel.swift index 3f40602e63..15941596bb 100644 --- a/damus/Models/ProfileModel.swift +++ b/damus/Models/ProfileModel.swift @@ -125,7 +125,7 @@ class ProfileModel: ObservableObject, Equatable { case .eose: let txn = NdbTxn(ndb: damus.ndb) if resp.subid == sub_id { - load_profiles(profiles_subid: prof_subid, relay_id: relay_id, load: .from_events(events.events), damus_state: damus, txn: txn) + load_profiles(context: "profile", profiles_subid: prof_subid, relay_id: relay_id, load: .from_events(events.events), damus_state: damus, txn: txn) } progress += 1 break diff --git a/damus/Models/SearchHomeModel.swift b/damus/Models/SearchHomeModel.swift index fdfa675193..ff78035afa 100644 --- a/damus/Models/SearchHomeModel.swift +++ b/damus/Models/SearchHomeModel.swift @@ -84,7 +84,7 @@ class SearchHomeModel: ObservableObject { unsubscribe(to: relay_id) let txn = NdbTxn(ndb: damus_state.ndb) - load_profiles(profiles_subid: profiles_subid, relay_id: relay_id, load: .from_events(events.all_events), damus_state: damus_state, txn: txn) + load_profiles(context: "universe", profiles_subid: profiles_subid, relay_id: relay_id, load: .from_events(events.all_events), damus_state: damus_state, txn: txn) } break @@ -127,14 +127,14 @@ enum PubkeysToLoad { case from_keys([Pubkey]) } -func load_profiles(profiles_subid: String, relay_id: String, load: PubkeysToLoad, damus_state: DamusState, txn: NdbTxn) { +func load_profiles(context: String, profiles_subid: String, relay_id: String, load: PubkeysToLoad, damus_state: DamusState, txn: NdbTxn) { let authors = find_profiles_to_fetch(profiles: damus_state.profiles, load: load, cache: damus_state.events, txn: txn) guard !authors.isEmpty else { return } - print("load_profiles: requesting \(authors.count) profiles from \(relay_id)") + print("load_profiles[\(context)]: requesting \(authors.count) profiles from \(relay_id)") let filter = NostrFilter(kinds: [.metadata], authors: authors) @@ -153,7 +153,7 @@ func load_profiles(profiles_subid: String, relay_id: String, load: PubkeysToL damus_state.ndb.write_profile_last_fetched(pubkey: ev.pubkey, fetched_at: now) } case .eose: - print("load_profiles: done loading \(authors.count) profiles from \(relay_id)") + print("load_profiles[\(context)]: done loading \(authors.count) profiles from \(relay_id)") damus_state.pool.unsubscribe(sub_id: profiles_subid, to: [relay_id]) case .ok: break diff --git a/damus/Models/SearchModel.swift b/damus/Models/SearchModel.swift index 0d945ca397..520ea7cf13 100644 --- a/damus/Models/SearchModel.swift +++ b/damus/Models/SearchModel.swift @@ -81,7 +81,7 @@ class SearchModel: ObservableObject { if sub_id == self.sub_id { let txn = NdbTxn(ndb: state.ndb) - load_profiles(profiles_subid: self.profiles_subid, relay_id: relay_id, load: .from_events(self.events.all_events), damus_state: state, txn: txn) + load_profiles(context: "search", profiles_subid: self.profiles_subid, relay_id: relay_id, load: .from_events(self.events.all_events), damus_state: state, txn: txn) } } } diff --git a/damus/Models/ThreadModel.swift b/damus/Models/ThreadModel.swift index 6b25bb2bc1..760b5010f1 100644 --- a/damus/Models/ThreadModel.swift +++ b/damus/Models/ThreadModel.swift @@ -121,7 +121,7 @@ class ThreadModel: ObservableObject { if sub_id == self.base_subid { let txn = NdbTxn(ndb: damus_state.ndb) - load_profiles(profiles_subid: self.profiles_subid, relay_id: relay_id, load: .from_events(Array(event_map)), damus_state: damus_state, txn: txn) + load_profiles(context: "thread", profiles_subid: self.profiles_subid, relay_id: relay_id, load: .from_events(Array(event_map)), damus_state: damus_state, txn: txn) } } diff --git a/damus/Models/ZapsModel.swift b/damus/Models/ZapsModel.swift index 9acc4778f0..2b1cb9fd3c 100644 --- a/damus/Models/ZapsModel.swift +++ b/damus/Models/ZapsModel.swift @@ -56,7 +56,7 @@ class ZapsModel: ObservableObject { case .eose: let events = state.events.lookup_zaps(target: target).map { $0.request.ev } let txn = NdbTxn(ndb: state.ndb) - load_profiles(profiles_subid: profiles_subid, relay_id: relay_id, load: .from_events(events), damus_state: state, txn: txn) + load_profiles(context: "zaps_model", profiles_subid: profiles_subid, relay_id: relay_id, load: .from_events(events), damus_state: state, txn: txn) case .event(_, let ev): guard ev.kind == 9735, let zapper = state.profiles.lookup_zapper(pubkey: target.pubkey),