Made a couple of minor fixes

• Fixed an issue with database error logging
• Fixed an issue with a missing join in the query to update the app badge count
pull/894/head
Morgan Pretty 8 months ago
parent 529cb2e0f9
commit 9081ff50f6

@ -523,6 +523,7 @@ public extension Interaction {
required: Interaction.thread required: Interaction.thread
.aliased(thread) .aliased(thread)
.joining(optional: SessionThread.contact) .joining(optional: SessionThread.contact)
.joining(optional: SessionThread.closedGroup)
.filter( .filter(
// Ignore muted threads // Ignore muted threads
SessionThread.Columns.mutedUntilTimestamp == nil || SessionThread.Columns.mutedUntilTimestamp == nil ||

@ -596,7 +596,7 @@ open class Storage {
static func logIfNeeded(_ error: Error, isWrite: Bool) { static func logIfNeeded(_ error: Error, isWrite: Bool) {
switch error { switch error {
case DatabaseError.SQLITE_ABORT, DatabaseError.SQLITE_INTERRUPT: case DatabaseError.SQLITE_ABORT, DatabaseError.SQLITE_INTERRUPT, DatabaseError.SQLITE_ERROR:
let message: String = ((error as? DatabaseError)?.message ?? "Unknown") let message: String = ((error as? DatabaseError)?.message ?? "Unknown")
Log.error(.storage, "Database \(isWrite ? "write" : "read") failed due to error: \(message)") Log.error(.storage, "Database \(isWrite ? "write" : "read") failed due to error: \(message)")
@ -659,8 +659,14 @@ open class Storage {
_ operation: @escaping (Database) throws -> T, _ operation: @escaping (Database) throws -> T,
_ completion: ((Result<T, Error>) -> Void)? = nil _ completion: ((Result<T, Error>) -> Void)? = nil
) -> Result<T, Error> { ) -> Result<T, Error> {
let semaphore: DispatchSemaphore? = (info.isAsync ? nil : DispatchSemaphore(value: 0))
var result: Result<T, Error> = .failure(StorageError.invalidQueryResult) var result: Result<T, Error> = .failure(StorageError.invalidQueryResult)
let semaphore: DispatchSemaphore? = (info.isAsync ? nil : DispatchSemaphore(value: 0))
let logErrorIfNeeded: (Result<T, Error>) -> () = { result in
switch result {
case .success: break
case .failure(let error): StorageState.logIfNeeded(error, isWrite: info.isWrite)
}
}
/// Perform the actual operation /// Perform the actual operation
switch (StorageState(info.storage), info.isWrite) { switch (StorageState(info.storage), info.isWrite) {
@ -674,6 +680,8 @@ open class Storage {
case .failure(let error): result = .failure(error) case .failure(let error): result = .failure(error)
} }
semaphore?.signal() semaphore?.signal()
if info.isAsync { logErrorIfNeeded(result) }
completion?(result) completion?(result)
} }
) )
@ -689,6 +697,8 @@ open class Storage {
result = .failure(error) result = .failure(error)
} }
semaphore?.signal() semaphore?.signal()
if info.isAsync { logErrorIfNeeded(result) }
completion?(result) completion?(result)
} }
} }
@ -697,12 +707,7 @@ open class Storage {
/// above closures to be sent /// above closures to be sent
semaphore?.wait() semaphore?.wait()
/// Log the error if needed if !info.isAsync { logErrorIfNeeded(result) }
switch result {
case .success: break
case .failure(let error): StorageState.logIfNeeded(error, isWrite: info.isWrite)
}
return result return result
} }

Loading…
Cancel
Save