Skip to content

Commit

Permalink
load_profiles: add context for debugging
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jb55 authored and suhailsaqan committed Oct 29, 2023
1 parent f9a7dee commit c80d9c2
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion damus/Models/EventsModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
6 changes: 3 additions & 3 deletions damus/Models/HomeModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion damus/Models/ProfileModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions damus/Models/SearchHomeModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion damus/Models/SearchModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion damus/Models/ThreadModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion damus/Models/ZapsModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit c80d9c2

Please sign in to comment.