nostrdb: close database when backgrounded

Otherwise iOS gets mad because we are holding onto a lockfile in a
shared container which is apparently not allowed.

Fixes: a1e6be214e ("Migrate NostrDB files to shared app group file container")
This commit is contained in:
William Casarin
2023-12-11 12:44:40 -08:00
parent c7cc8df5ba
commit da2bdad18d
3 changed files with 67 additions and 8 deletions

View File

@@ -29,7 +29,14 @@ class NdbTxn<T> {
self.inherited = true
} else {
self.txn = ndb_txn()
let _ = ndb_begin_query(ndb.ndb.ndb, &self.txn)
let ok = ndb_begin_query(ndb.ndb.ndb, &self.txn) != 0
if !ok {
self.moved = false
self.txn = ndb_txn()
self.inherited = true
self.val = with(self)
return
}
Thread.current.threadDictionary["ndb_txn"] = self.txn
self.inherited = false
}