commit 4389cc2128769b297207fc6de6fe0ebb2e96f973
parent 76508dbbfd7277a3ca0b41cbf1d3dd0fef6ad218
Author: William Casarin <jb55@jb55.com>
Date: Mon, 23 Oct 2023 11:21:37 +0800
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.
Diffstat:
7 files changed, 12 insertions(+), 12 deletions(-)
diff --git 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
@@ -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
@@ -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
@@ -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<Y>(profiles_subid: String, relay_id: String, load: PubkeysToLoad, damus_state: DamusState, txn: NdbTxn<Y>) {
+func load_profiles<Y>(context: String, profiles_subid: String, relay_id: String, load: PubkeysToLoad, damus_state: DamusState, txn: NdbTxn<Y>) {
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<Y>(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
@@ -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
@@ -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
@@ -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),