ndb/txn: make transactions failable
Since there may be situations where we close and re-open the database,
we need to make sure transactions fail when the database is not open.
Make NdbTxn an init?() constructor and check for ndb.closed. If it's
closed, then fail transaction construction.
This fixes crashes during high database activity when switching from
background to foreground and vice-versa.
Fixes: da2bdad18d ("nostrdb: close database when backgrounded")
This commit is contained in:
@@ -17,7 +17,7 @@ struct UserSearch: View {
|
||||
@EnvironmentObject var tagModel: TagModel
|
||||
|
||||
var users: [Pubkey] {
|
||||
let txn = NdbTxn(ndb: damus_state.ndb)
|
||||
guard let txn = NdbTxn(ndb: damus_state.ndb) else { return [] }
|
||||
return search_profiles(profiles: damus_state.profiles, search: search, txn: txn).sorted { a, b in
|
||||
let aFriendTypePriority = get_friend_type(contacts: damus_state.contacts, pubkey: a)?.priority ?? 0
|
||||
let bFriendTypePriority = get_friend_type(contacts: damus_state.contacts, pubkey: b)?.priority ?? 0
|
||||
@@ -33,7 +33,7 @@ struct UserSearch: View {
|
||||
|
||||
func on_user_tapped(pk: Pubkey) {
|
||||
let profile_txn = damus_state.profiles.lookup(id: pk)
|
||||
let profile = profile_txn.unsafeUnownedValue
|
||||
let profile = profile_txn?.unsafeUnownedValue
|
||||
let user_tag = user_tag_attr_string(profile: profile, pubkey: pk)
|
||||
|
||||
appendUserTag(withTag: user_tag)
|
||||
|
||||
Reference in New Issue
Block a user