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 4 months ago
parent 529cb2e0f9
commit 9081ff50f6

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

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

Loading…
Cancel
Save