debug: add some transaction debugging
This commit is contained in:
@@ -462,23 +462,27 @@ struct ContentView: View {
|
|||||||
damus_state.pool.disconnect()
|
damus_state.pool.disconnect()
|
||||||
}
|
}
|
||||||
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { obj in
|
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { obj in
|
||||||
print("📙 DAMUS ACTIVE NOTIFY")
|
print("txn: 📙 DAMUS ACTIVE NOTIFY")
|
||||||
try? damus_state.ndb.reopen()
|
if damus_state.ndb.reopen() {
|
||||||
|
print("txn: NOSTRDB REOPENED")
|
||||||
|
} else {
|
||||||
|
print("txn: NOSTRDB FAILED TO REOPEN closed:\(damus_state.ndb.closed)")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.onChange(of: scenePhase) { (phase: ScenePhase) in
|
.onChange(of: scenePhase) { (phase: ScenePhase) in
|
||||||
guard let damus_state else { return }
|
guard let damus_state else { return }
|
||||||
switch phase {
|
switch phase {
|
||||||
case .background:
|
case .background:
|
||||||
print("📙 DAMUS BACKGROUNDED")
|
print("txn: 📙 DAMUS BACKGROUNDED")
|
||||||
Task { @MainActor in
|
Task { @MainActor in
|
||||||
damus_state.ndb.close()
|
damus_state.ndb.close()
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case .inactive:
|
case .inactive:
|
||||||
print("📙 DAMUS INACTIVE")
|
print("txn: 📙 DAMUS INACTIVE")
|
||||||
break
|
break
|
||||||
case .active:
|
case .active:
|
||||||
print("📙 DAMUS ACTIVE")
|
print("txn: 📙 DAMUS ACTIVE")
|
||||||
damus_state.pool.ping()
|
damus_state.pool.ping()
|
||||||
@unknown default:
|
@unknown default:
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ struct DamusState: HeadlessDamusState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func close() {
|
func close() {
|
||||||
|
print("txn: damus close")
|
||||||
pool.close()
|
pool.close()
|
||||||
ndb.close()
|
ndb.close()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -178,17 +178,20 @@ class Ndb {
|
|||||||
func close() {
|
func close() {
|
||||||
guard !self.closed else { return }
|
guard !self.closed else { return }
|
||||||
self.closed = true
|
self.closed = true
|
||||||
|
print("txn: CLOSING NOSTRDB")
|
||||||
ndb_destroy(self.ndb.ndb)
|
ndb_destroy(self.ndb.ndb)
|
||||||
|
print("txn: NOSTRDB CLOSED")
|
||||||
}
|
}
|
||||||
|
|
||||||
func reopen() throws {
|
func reopen() -> Bool {
|
||||||
guard self.closed,
|
guard self.closed,
|
||||||
let db = Self.open(path: self.path, owns_db_file: self.owns_db) else {
|
let db = Self.open(path: self.path, owns_db_file: self.owns_db) else {
|
||||||
throw DatabaseError.failed_open
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
self.closed = false
|
self.closed = false
|
||||||
self.ndb = db
|
self.ndb = db
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func lookup_note_by_key_with_txn<Y>(_ key: NoteKey, txn: NdbTxn<Y>) -> NdbNote? {
|
func lookup_note_by_key_with_txn<Y>(_ key: NoteKey, txn: NdbTxn<Y>) -> NdbNote? {
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class NdbTxn<T> {
|
|||||||
|
|
||||||
#if TXNDEBUG
|
#if TXNDEBUG
|
||||||
txn_count -= 1;
|
txn_count -= 1;
|
||||||
print("closing transaction \(txn_count)")
|
print("txn: closing transaction \(txn_count)")
|
||||||
#endif
|
#endif
|
||||||
ndb_end_query(&self.txn)
|
ndb_end_query(&self.txn)
|
||||||
Thread.current.threadDictionary.removeObject(forKey: "ndb_txn")
|
Thread.current.threadDictionary.removeObject(forKey: "ndb_txn")
|
||||||
|
|||||||
Reference in New Issue
Block a user