commit 909701ce7b29eae173b02cac2b89e23104e5a756
parent 54674104ead99aea9f7ab11461ab443b894b6b0d
Author: William Casarin <jb55@jb55.com>
Date: Wed, 10 Jan 2024 11:32:38 -0800
profile: partially fix performance regression
This will be completely fixed once we switch to stored note blocks
Diffstat:
2 files changed, 15 insertions(+), 3 deletions(-)
diff --git a/damus/Models/ContentFilters.swift b/damus/Models/ContentFilters.swift
@@ -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)
}
}
diff --git a/nostrdb/NdbNote+.swift b/nostrdb/NdbNote+.swift
@@ -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()
}
}