profile: partially fix performance regression

This will be completely fixed once we switch to stored note blocks
This commit is contained in:
William Casarin 2024-01-10 11:32:38 -08:00
parent 54674104ea
commit 909701ce7b
2 changed files with 15 additions and 3 deletions

View File

@ -31,7 +31,8 @@ func nsfw_tag_filter(ev: NostrEvent) -> Bool {
func get_repost_of_muted_user_filter(damus_state: DamusState) -> ((_ ev: NostrEvent) -> Bool) {
return { ev in
guard ev.known_kind == .boost else { return true }
guard let inner_ev = ev.get_inner_event(cache: damus_state.events) else { return true }
// This needs to use cached because it can be way too slow otherwise
guard let inner_ev = ev.get_cached_inner_event(cache: damus_state.events) else { return true }
return should_show_event(keypair: damus_state.keypair, hellthreads: damus_state.muted_threads, contacts: damus_state.contacts, ev: inner_ev)
}
}

View File

@ -9,7 +9,11 @@ import Foundation
// Extension to make NdbNote compatible with NostrEvent's original API
extension NdbNote {
func get_inner_event(cache: EventCache) -> NdbNote? {
func parse_inner_event() -> NdbNote? {
return NdbNote.owned_from_json_cstr(json: content_raw, json_len: content_len)
}
func get_cached_inner_event(cache: EventCache) -> NdbNote? {
guard self.known_kind == .boost else {
return nil
}
@ -19,6 +23,13 @@ extension NdbNote {
return cache.lookup(id)
}
return self.get_inner_event()
return nil
}
func get_inner_event(cache: EventCache) -> NdbNote? {
if let ev = get_cached_inner_event(cache: cache) {
return ev
}
return self.parse_inner_event()
}
}