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:
@@ -78,11 +78,12 @@ struct BannerImageView: View {
|
||||
var body: some View {
|
||||
InnerBannerImageView(disable_animation: disable_animation, url: get_banner_url(banner: banner, pubkey: pubkey, profiles: profiles))
|
||||
.onReceive(handle_notify(.profile_updated)) { updated in
|
||||
guard updated.pubkey == self.pubkey else {
|
||||
guard updated.pubkey == self.pubkey,
|
||||
let profile_txn = profiles.lookup(id: updated.pubkey)
|
||||
else {
|
||||
return
|
||||
}
|
||||
|
||||
let profile_txn = profiles.lookup(id: updated.pubkey)
|
||||
let profile = profile_txn.unsafeUnownedValue
|
||||
if let bannerImage = profile?.banner, bannerImage != self.banner {
|
||||
self.banner = bannerImage
|
||||
@@ -92,7 +93,7 @@ struct BannerImageView: View {
|
||||
}
|
||||
|
||||
func get_banner_url(banner: String?, pubkey: Pubkey, profiles: Profiles) -> URL? {
|
||||
let bannerUrlString = banner ?? profiles.lookup(id: pubkey).map({ p in p?.banner }).value ?? ""
|
||||
let bannerUrlString = banner ?? profiles.lookup(id: pubkey)?.map({ p in p?.banner }).value ?? ""
|
||||
if let url = URL(string: bannerUrlString) {
|
||||
return url
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user