From 9081ff50f628029e4a68a128a0a7884ba0423a86 Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Tue, 4 Feb 2025 12:21:00 +1100 Subject: [PATCH] Made a couple of minor fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Fixed an issue with database error logging • Fixed an issue with a missing join in the query to update the app badge count --- .../Database/Models/Interaction.swift | 1 + SessionUtilitiesKit/Database/Storage.swift | 21 ++++++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/SessionMessagingKit/Database/Models/Interaction.swift b/SessionMessagingKit/Database/Models/Interaction.swift index e2082db33..924cdf50d 100644 --- a/SessionMessagingKit/Database/Models/Interaction.swift +++ b/SessionMessagingKit/Database/Models/Interaction.swift @@ -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 || diff --git a/SessionUtilitiesKit/Database/Storage.swift b/SessionUtilitiesKit/Database/Storage.swift index 93d0aba6a..4a9001b19 100644 --- a/SessionUtilitiesKit/Database/Storage.swift +++ b/SessionUtilitiesKit/Database/Storage.swift @@ -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) -> Void)? = nil ) -> Result { - let semaphore: DispatchSemaphore? = (info.isAsync ? nil : DispatchSemaphore(value: 0)) var result: Result = .failure(StorageError.invalidQueryResult) + let semaphore: DispatchSemaphore? = (info.isAsync ? nil : DispatchSemaphore(value: 0)) + let logErrorIfNeeded: (Result) -> () = { 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 }