From 4ac3da76121eebcf794b7ac5e8b68bbebcdf88eb Mon Sep 17 00:00:00 2001 From: William Casarin Date: Thu, 9 May 2024 14:34:02 -0700 Subject: [PATCH] events: try nostrdb cache if we don't have one in-memory Our nip10 logic looks for notes only in the in-memory cache. This means sometimes threads don't get fully loaded if for whatever reason it's in the nostrdb cache but not in-memory. Ideally we would just remove our in-memory cache, but for now let's just hack it so it falls back to nostrdb and makes an owned note. Changelog-Fixed: Fixed threads not loading sometimes Signed-off-by: William Casarin --- damus/Util/EventCache.swift | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/damus/Util/EventCache.swift b/damus/Util/EventCache.swift index 2ea0ab68..23dab3a2 100644 --- a/damus/Util/EventCache.swift +++ b/damus/Util/EventCache.swift @@ -218,7 +218,16 @@ class EventCache { */ func lookup(_ evid: NoteId) -> NostrEvent? { - return events[evid] + if let ev = events[evid] { + return ev + } + + if let ev = self.ndb.lookup_note(evid)?.unsafeUnownedValue?.to_owned() { + events[ev.id] = ev + return ev + } + + return nil } func insert(_ ev: NostrEvent) {