mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-03 18:56:14 +00:00
Finish converting SyncDatabase to actor.
This commit is contained in:
1 parent
d44382df31
commit
dbef575b25
7 files changed
+83
-230
No files matched your search
@@ -274,7 +274,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSUserInterfaceValidat
|
||||
}
|
||||
|
||||
func application(_ application: NSApplication, didReceiveRemoteNotification userInfo: [String : Any]) {
|
||||
Task {
|
||||
Task { @MainActor in
|
||||
await AccountManager.shared.receiveRemoteNotification(userInfo: userInfo)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,7 +277,7 @@ public final class AccountManager: UnreadCountProvider {
|
||||
|
||||
combinedRefreshProgress.start()
|
||||
|
||||
Task {
|
||||
Task { @MainActor in
|
||||
await withTaskGroup(of: Void.self) { group in
|
||||
for account in activeAccounts {
|
||||
group.addTask {
|
||||
|
||||
+65
-217
@@ -12,7 +12,7 @@ import SyncDatabase
|
||||
import Articles
|
||||
import RSCore
|
||||
|
||||
final class FeedlySendArticleStatusesOperationTests: XCTestCase {
|
||||
@MainActor final class FeedlySendArticleStatusesOperationTests: XCTestCase {
|
||||
|
||||
private var account: Account!
|
||||
private let support = FeedlyTestSupport()
|
||||
@@ -32,7 +32,7 @@ final class FeedlySendArticleStatusesOperationTests: XCTestCase {
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
func testSendEmpty() {
|
||||
func testSendEmpty() async {
|
||||
let service = TestMarkArticlesService()
|
||||
let send = FeedlySendArticleStatusesOperation(database: container.database, service: service)
|
||||
|
||||
@@ -43,20 +43,14 @@ final class FeedlySendArticleStatusesOperationTests: XCTestCase {
|
||||
|
||||
MainThreadOperationQueue.shared.add(send)
|
||||
|
||||
waitForExpectations(timeout: 2)
|
||||
await fulfillment(of: [didFinishExpectation], timeout: 2)
|
||||
}
|
||||
|
||||
func testSendUnreadSuccess() {
|
||||
func testSendUnreadSuccess() async throws {
|
||||
let articleIds = Set((0..<100).map { "feed/0/article/\($0)" })
|
||||
let statuses = articleIds.map { SyncStatus(articleID: $0, key: .read, flag: false) }
|
||||
let statuses = Set(articleIds.map { SyncStatus(articleID: $0, key: .read, flag: false) })
|
||||
|
||||
let insertExpectation = expectation(description: "Inserted Statuses")
|
||||
container.database.insertStatuses(statuses) { error in
|
||||
XCTAssertNil(error)
|
||||
insertExpectation.fulfill()
|
||||
}
|
||||
|
||||
waitForExpectations(timeout: 2)
|
||||
try await container.database.insertStatuses(statuses)
|
||||
|
||||
let service = TestMarkArticlesService()
|
||||
service.mockResult = .success(())
|
||||
@@ -71,35 +65,18 @@ final class FeedlySendArticleStatusesOperationTests: XCTestCase {
|
||||
send.completionBlock = { _ in
|
||||
didFinishExpectation.fulfill()
|
||||
}
|
||||
|
||||
MainThreadOperationQueue.shared.add(send)
|
||||
await fulfillment(of: [didFinishExpectation], timeout: 2)
|
||||
|
||||
waitForExpectations(timeout: 2)
|
||||
|
||||
let selectPendingCountExpectation = expectation(description: "Did Select Pending Count")
|
||||
container.database.selectPendingCount { result in
|
||||
do {
|
||||
let statusCount = try result.get()
|
||||
XCTAssertEqual(statusCount, 0)
|
||||
selectPendingCountExpectation.fulfill()
|
||||
} catch {
|
||||
XCTFail("Error unwrapping database result: \(error)")
|
||||
}
|
||||
}
|
||||
waitForExpectations(timeout: 2)
|
||||
let statusCount = try await container.database.selectPendingCount()
|
||||
XCTAssertEqual(statusCount, 0)
|
||||
}
|
||||
|
||||
func testSendUnreadFailure() {
|
||||
func testSendUnreadFailure() async throws {
|
||||
let articleIds = Set((0..<100).map { "feed/0/article/\($0)" })
|
||||
let statuses = articleIds.map { SyncStatus(articleID: $0, key: .read, flag: false) }
|
||||
let statuses = Set(articleIds.map { SyncStatus(articleID: $0, key: .read, flag: false) })
|
||||
|
||||
let insertExpectation = expectation(description: "Inserted Statuses")
|
||||
container.database.insertStatuses(statuses) { error in
|
||||
XCTAssertNil(error)
|
||||
insertExpectation.fulfill()
|
||||
}
|
||||
|
||||
waitForExpectations(timeout: 2)
|
||||
try await container.database.insertStatuses(statuses)
|
||||
|
||||
let service = TestMarkArticlesService()
|
||||
service.mockResult = .failure(URLError(.timedOut))
|
||||
@@ -117,32 +94,17 @@ final class FeedlySendArticleStatusesOperationTests: XCTestCase {
|
||||
|
||||
MainThreadOperationQueue.shared.add(send)
|
||||
|
||||
waitForExpectations(timeout: 2)
|
||||
await fulfillment(of: [didFinishExpectation], timeout: 2)
|
||||
|
||||
let selectPendingCountExpectation = expectation(description: "Did Select Pending Count")
|
||||
container.database.selectPendingCount { result in
|
||||
do {
|
||||
let statusCount = try result.get()
|
||||
XCTAssertEqual(statusCount, statuses.count)
|
||||
selectPendingCountExpectation.fulfill()
|
||||
} catch {
|
||||
XCTFail("Error unwrapping database result: \(error)")
|
||||
}
|
||||
}
|
||||
waitForExpectations(timeout: 2)
|
||||
let statusCount = try await container.database.selectPendingCount()
|
||||
XCTAssertEqual(statusCount, statuses.count)
|
||||
}
|
||||
|
||||
func testSendReadSuccess() {
|
||||
func testSendReadSuccess() async throws {
|
||||
let articleIds = Set((0..<100).map { "feed/0/article/\($0)" })
|
||||
let statuses = articleIds.map { SyncStatus(articleID: $0, key: .read, flag: true) }
|
||||
let statuses = Set(articleIds.map { SyncStatus(articleID: $0, key: .read, flag: true) })
|
||||
|
||||
let insertExpectation = expectation(description: "Inserted Statuses")
|
||||
container.database.insertStatuses(statuses) { error in
|
||||
XCTAssertNil(error)
|
||||
insertExpectation.fulfill()
|
||||
}
|
||||
|
||||
waitForExpectations(timeout: 2)
|
||||
try await container.database.insertStatuses(statuses)
|
||||
|
||||
let service = TestMarkArticlesService()
|
||||
service.mockResult = .success(())
|
||||
@@ -160,32 +122,17 @@ final class FeedlySendArticleStatusesOperationTests: XCTestCase {
|
||||
|
||||
MainThreadOperationQueue.shared.add(send)
|
||||
|
||||
waitForExpectations(timeout: 2)
|
||||
await fulfillment(of: [didFinishExpectation], timeout: 2)
|
||||
|
||||
let selectPendingCountExpectation = expectation(description: "Did Select Pending Count")
|
||||
container.database.selectPendingCount { result in
|
||||
do {
|
||||
let statusCount = try result.get()
|
||||
XCTAssertEqual(statusCount, 0)
|
||||
selectPendingCountExpectation.fulfill()
|
||||
} catch {
|
||||
XCTFail("Error unwrapping database result: \(error)")
|
||||
}
|
||||
}
|
||||
waitForExpectations(timeout: 2)
|
||||
let statusCount = try await container.database.selectPendingCount()
|
||||
XCTAssertEqual(statusCount, 0)
|
||||
}
|
||||
|
||||
func testSendReadFailure() {
|
||||
func testSendReadFailure() async throws {
|
||||
let articleIds = Set((0..<100).map { "feed/0/article/\($0)" })
|
||||
let statuses = articleIds.map { SyncStatus(articleID: $0, key: .read, flag: true) }
|
||||
let statuses = Set(articleIds.map { SyncStatus(articleID: $0, key: .read, flag: true) })
|
||||
|
||||
let insertExpectation = expectation(description: "Inserted Statuses")
|
||||
container.database.insertStatuses(statuses) { error in
|
||||
XCTAssertNil(error)
|
||||
insertExpectation.fulfill()
|
||||
}
|
||||
|
||||
waitForExpectations(timeout: 2)
|
||||
try await container.database.insertStatuses(statuses)
|
||||
|
||||
let service = TestMarkArticlesService()
|
||||
service.mockResult = .failure(URLError(.timedOut))
|
||||
@@ -203,32 +150,17 @@ final class FeedlySendArticleStatusesOperationTests: XCTestCase {
|
||||
|
||||
MainThreadOperationQueue.shared.add(send)
|
||||
|
||||
waitForExpectations(timeout: 2)
|
||||
await fulfillment(of: [didFinishExpectation], timeout: 2)
|
||||
|
||||
let selectPendingCountExpectation = expectation(description: "Did Select Pending Count")
|
||||
container.database.selectPendingCount { result in
|
||||
do {
|
||||
let statusCount = try result.get()
|
||||
XCTAssertEqual(statusCount, statuses.count)
|
||||
selectPendingCountExpectation.fulfill()
|
||||
} catch {
|
||||
XCTFail("Error unwrapping database result: \(error)")
|
||||
}
|
||||
}
|
||||
waitForExpectations(timeout: 2)
|
||||
let statusCount = try await container.database.selectPendingCount()
|
||||
XCTAssertEqual(statusCount, statuses.count)
|
||||
}
|
||||
|
||||
func testSendStarredSuccess() {
|
||||
func testSendStarredSuccess() async throws {
|
||||
let articleIds = Set((0..<100).map { "feed/0/article/\($0)" })
|
||||
let statuses = articleIds.map { SyncStatus(articleID: $0, key: .starred, flag: true) }
|
||||
let statuses = Set(articleIds.map { SyncStatus(articleID: $0, key: .starred, flag: true) })
|
||||
|
||||
let insertExpectation = expectation(description: "Inserted Statuses")
|
||||
container.database.insertStatuses(statuses) { error in
|
||||
XCTAssertNil(error)
|
||||
insertExpectation.fulfill()
|
||||
}
|
||||
|
||||
waitForExpectations(timeout: 2)
|
||||
try await container.database.insertStatuses(statuses)
|
||||
|
||||
let service = TestMarkArticlesService()
|
||||
service.mockResult = .success(())
|
||||
@@ -246,32 +178,17 @@ final class FeedlySendArticleStatusesOperationTests: XCTestCase {
|
||||
|
||||
MainThreadOperationQueue.shared.add(send)
|
||||
|
||||
waitForExpectations(timeout: 2)
|
||||
await fulfillment(of: [didFinishExpectation], timeout: 2)
|
||||
|
||||
let selectPendingCountExpectation = expectation(description: "Did Select Pending Count")
|
||||
container.database.selectPendingCount { result in
|
||||
do {
|
||||
let statusCount = try result.get()
|
||||
XCTAssertEqual(statusCount, 0)
|
||||
selectPendingCountExpectation.fulfill()
|
||||
} catch {
|
||||
XCTFail("Error unwrapping database result: \(error)")
|
||||
}
|
||||
}
|
||||
waitForExpectations(timeout: 2)
|
||||
let statusCount = try await container.database.selectPendingCount()
|
||||
XCTAssertEqual(statusCount, 0)
|
||||
}
|
||||
|
||||
func testSendStarredFailure() {
|
||||
func testSendStarredFailure() async throws {
|
||||
let articleIds = Set((0..<100).map { "feed/0/article/\($0)" })
|
||||
let statuses = articleIds.map { SyncStatus(articleID: $0, key: .starred, flag: true) }
|
||||
let statuses = Set(articleIds.map { SyncStatus(articleID: $0, key: .starred, flag: true) })
|
||||
|
||||
let insertExpectation = expectation(description: "Inserted Statuses")
|
||||
container.database.insertStatuses(statuses) { error in
|
||||
XCTAssertNil(error)
|
||||
insertExpectation.fulfill()
|
||||
}
|
||||
|
||||
waitForExpectations(timeout: 2)
|
||||
try await container.database.insertStatuses(statuses)
|
||||
|
||||
let service = TestMarkArticlesService()
|
||||
service.mockResult = .failure(URLError(.timedOut))
|
||||
@@ -289,32 +206,17 @@ final class FeedlySendArticleStatusesOperationTests: XCTestCase {
|
||||
|
||||
MainThreadOperationQueue.shared.add(send)
|
||||
|
||||
waitForExpectations(timeout: 2)
|
||||
await fulfillment(of: [didFinishExpectation], timeout: 2)
|
||||
|
||||
let selectPendingCountExpectation = expectation(description: "Did Select Pending Count")
|
||||
container.database.selectPendingCount { result in
|
||||
do {
|
||||
let statusCount = try result.get()
|
||||
XCTAssertEqual(statusCount, statuses.count)
|
||||
selectPendingCountExpectation.fulfill()
|
||||
} catch {
|
||||
XCTFail("Error unwrapping database result: \(error)")
|
||||
}
|
||||
}
|
||||
waitForExpectations(timeout: 2)
|
||||
let statusCount = try await container.database.selectPendingCount()
|
||||
XCTAssertEqual(statusCount, statuses.count)
|
||||
}
|
||||
|
||||
func testSendUnstarredSuccess() {
|
||||
func testSendUnstarredSuccess() async throws {
|
||||
let articleIds = Set((0..<100).map { "feed/0/article/\($0)" })
|
||||
let statuses = articleIds.map { SyncStatus(articleID: $0, key: .starred, flag: false) }
|
||||
let statuses = Set(articleIds.map { SyncStatus(articleID: $0, key: .starred, flag: false) })
|
||||
|
||||
let insertExpectation = expectation(description: "Inserted Statuses")
|
||||
container.database.insertStatuses(statuses) { error in
|
||||
XCTAssertNil(error)
|
||||
insertExpectation.fulfill()
|
||||
}
|
||||
|
||||
waitForExpectations(timeout: 2)
|
||||
try await container.database.insertStatuses(statuses)
|
||||
|
||||
let service = TestMarkArticlesService()
|
||||
service.mockResult = .success(())
|
||||
@@ -332,32 +234,17 @@ final class FeedlySendArticleStatusesOperationTests: XCTestCase {
|
||||
|
||||
MainThreadOperationQueue.shared.add(send)
|
||||
|
||||
waitForExpectations(timeout: 2)
|
||||
await fulfillment(of: [didFinishExpectation], timeout: 2)
|
||||
|
||||
let selectPendingCountExpectation = expectation(description: "Did Select Pending Count")
|
||||
container.database.selectPendingCount { result in
|
||||
do {
|
||||
let statusCount = try result.get()
|
||||
XCTAssertEqual(statusCount, 0)
|
||||
selectPendingCountExpectation.fulfill()
|
||||
} catch {
|
||||
XCTFail("Error unwrapping database result: \(error)")
|
||||
}
|
||||
}
|
||||
waitForExpectations(timeout: 2)
|
||||
let statusCount = try await container.database.selectPendingCount()
|
||||
XCTAssertEqual(statusCount, 0)
|
||||
}
|
||||
|
||||
func testSendUnstarredFailure() {
|
||||
func testSendUnstarredFailure() async throws {
|
||||
let articleIds = Set((0..<100).map { "feed/0/article/\($0)" })
|
||||
let statuses = articleIds.map { SyncStatus(articleID: $0, key: .starred, flag: false) }
|
||||
let statuses = Set(articleIds.map { SyncStatus(articleID: $0, key: .starred, flag: false) })
|
||||
|
||||
let insertExpectation = expectation(description: "Inserted Statuses")
|
||||
container.database.insertStatuses(statuses) { error in
|
||||
XCTAssertNil(error)
|
||||
insertExpectation.fulfill()
|
||||
}
|
||||
|
||||
waitForExpectations(timeout: 2)
|
||||
try await container.database.insertStatuses(statuses)
|
||||
|
||||
let service = TestMarkArticlesService()
|
||||
service.mockResult = .failure(URLError(.timedOut))
|
||||
@@ -375,39 +262,24 @@ final class FeedlySendArticleStatusesOperationTests: XCTestCase {
|
||||
|
||||
MainThreadOperationQueue.shared.add(send)
|
||||
|
||||
waitForExpectations(timeout: 2)
|
||||
await fulfillment(of: [didFinishExpectation], timeout: 2)
|
||||
|
||||
let selectPendingCountExpectation = expectation(description: "Did Select Pending Count")
|
||||
container.database.selectPendingCount { result in
|
||||
do {
|
||||
let expectedCount = try result.get()
|
||||
XCTAssertEqual(expectedCount, statuses.count)
|
||||
selectPendingCountExpectation.fulfill()
|
||||
} catch {
|
||||
XCTFail("Error unwrapping database result: \(error)")
|
||||
}
|
||||
}
|
||||
waitForExpectations(timeout: 2)
|
||||
let statusCount = try await container.database.selectPendingCount()
|
||||
XCTAssertEqual(statusCount, statuses.count)
|
||||
}
|
||||
|
||||
func testSendAllSuccess() {
|
||||
func testSendAllSuccess() async throws {
|
||||
let articleIds = Set((0..<100).map { "feed/0/article/\($0)" })
|
||||
let keys = [SyncStatus.Key.read, .starred]
|
||||
let flags = [true, false]
|
||||
let statuses = articleIds.map { articleId -> SyncStatus in
|
||||
let statuses = Set(articleIds.map { articleId -> SyncStatus in
|
||||
let key = keys.randomElement()!
|
||||
let flag = flags.randomElement()!
|
||||
let status = SyncStatus(articleID: articleId, key: key, flag: flag)
|
||||
return status
|
||||
}
|
||||
})
|
||||
|
||||
let insertExpectation = expectation(description: "Inserted Statuses")
|
||||
container.database.insertStatuses(statuses) { error in
|
||||
XCTAssertNil(error)
|
||||
insertExpectation.fulfill()
|
||||
}
|
||||
|
||||
waitForExpectations(timeout: 2)
|
||||
try await container.database.insertStatuses(statuses)
|
||||
|
||||
let service = TestMarkArticlesService()
|
||||
service.mockResult = .success(())
|
||||
@@ -435,39 +307,24 @@ final class FeedlySendArticleStatusesOperationTests: XCTestCase {
|
||||
|
||||
MainThreadOperationQueue.shared.add(send)
|
||||
|
||||
waitForExpectations(timeout: 2)
|
||||
await fulfillment(of: [didFinishExpectation], timeout: 2)
|
||||
|
||||
let selectPendingCountExpectation = expectation(description: "Did Select Pending Count")
|
||||
container.database.selectPendingCount { result in
|
||||
do {
|
||||
let statusCount = try result.get()
|
||||
XCTAssertEqual(statusCount, 0)
|
||||
selectPendingCountExpectation.fulfill()
|
||||
} catch {
|
||||
XCTFail("Error unwrapping database result: \(error)")
|
||||
}
|
||||
}
|
||||
waitForExpectations(timeout: 2)
|
||||
let statusCount = try await container.database.selectPendingCount()
|
||||
XCTAssertEqual(statusCount, 0)
|
||||
}
|
||||
|
||||
func testSendAllFailure() {
|
||||
func testSendAllFailure() async throws {
|
||||
let articleIds = Set((0..<100).map { "feed/0/article/\($0)" })
|
||||
let keys = [SyncStatus.Key.read, .starred]
|
||||
let flags = [true, false]
|
||||
let statuses = articleIds.map { articleId -> SyncStatus in
|
||||
let statuses = Set(articleIds.map { articleId -> SyncStatus in
|
||||
let key = keys.randomElement()!
|
||||
let flag = flags.randomElement()!
|
||||
let status = SyncStatus(articleID: articleId, key: key, flag: flag)
|
||||
return status
|
||||
}
|
||||
})
|
||||
|
||||
let insertExpectation = expectation(description: "Inserted Statuses")
|
||||
container.database.insertStatuses(statuses) { error in
|
||||
XCTAssertNil(error)
|
||||
insertExpectation.fulfill()
|
||||
}
|
||||
|
||||
waitForExpectations(timeout: 2)
|
||||
try await container.database.insertStatuses(statuses)
|
||||
|
||||
let service = TestMarkArticlesService()
|
||||
service.mockResult = .failure(URLError(.timedOut))
|
||||
@@ -496,18 +353,9 @@ final class FeedlySendArticleStatusesOperationTests: XCTestCase {
|
||||
|
||||
MainThreadOperationQueue.shared.add(send)
|
||||
|
||||
waitForExpectations(timeout: 2)
|
||||
await fulfillment(of: [didFinishExpectation], timeout: 2)
|
||||
|
||||
let selectPendingCountExpectation = expectation(description: "Did Select Pending Count")
|
||||
container.database.selectPendingCount { result in
|
||||
do {
|
||||
let statusCount = try result.get()
|
||||
XCTAssertEqual(statusCount, statuses.count)
|
||||
selectPendingCountExpectation.fulfill()
|
||||
} catch {
|
||||
XCTFail("Error unwrapping database result: \(error)")
|
||||
}
|
||||
}
|
||||
waitForExpectations(timeout: 2)
|
||||
let statusCount = try await container.database.selectPendingCount()
|
||||
XCTAssertEqual(statusCount, statuses.count)
|
||||
}
|
||||
}
|
||||
@@ -65,7 +65,7 @@ final class FeedlyTestSupport {
|
||||
init() {
|
||||
let dataFolder = try! FileManager.default.url(for: .cachesDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
|
||||
path = dataFolder.appendingPathComponent("\(UUID().uuidString)-Sync.sqlite3").path
|
||||
database = SyncDatabase(databaseFilePath: path)
|
||||
database = SyncDatabase(databasePath: path)
|
||||
}
|
||||
|
||||
deinit {
|
||||
|
||||
@@ -133,7 +133,6 @@ public final class DatabaseQueue {
|
||||
/// Nevertheless, it’s best to avoid this because it will block the main thread —
|
||||
/// prefer the async `runInTransaction` instead.
|
||||
public func runInTransactionSync(_ databaseBlock: @escaping DatabaseBlock) {
|
||||
precondition(Thread.isMainThread)
|
||||
serialDispatchQueue.sync {
|
||||
self._runInDatabase(self.database, databaseBlock, true)
|
||||
}
|
||||
@@ -142,7 +141,6 @@ public final class DatabaseQueue {
|
||||
/// Run a DatabaseBlock wrapped in a transaction asynchronously.
|
||||
/// Transactions help performance significantly when updating the database.
|
||||
public func runInTransaction(_ databaseBlock: @escaping DatabaseBlock) {
|
||||
precondition(Thread.isMainThread)
|
||||
serialDispatchQueue.async {
|
||||
self._runInDatabase(self.database, databaseBlock, true)
|
||||
}
|
||||
|
||||
@@ -22,7 +22,10 @@ public extension FMDatabase {
|
||||
|
||||
func executeUpdateInTransaction(_ sql : String, withArgumentsIn parameters: [Any]? = nil) {
|
||||
beginTransaction()
|
||||
executeUpdate(sql, withArgumentsIn: parameters)
|
||||
guard executeUpdate(sql, withArgumentsIn: parameters) else {
|
||||
rollback()
|
||||
return
|
||||
}
|
||||
commit()
|
||||
}
|
||||
|
||||
|
||||
@@ -16,12 +16,12 @@ struct SyncStatusTable {
|
||||
|
||||
static func selectForProcessing(limit: Int?, database: FMDatabase) -> Set<SyncStatus>? {
|
||||
database.beginTransaction()
|
||||
defer {
|
||||
database.commit()
|
||||
}
|
||||
|
||||
let updateSQL = "update \(name) set selected = true"
|
||||
database.executeUpdate(updateSQL, withArgumentsIn: nil)
|
||||
guard database.executeUpdate(updateSQL, withArgumentsIn: nil) else {
|
||||
database.rollback()
|
||||
return nil
|
||||
}
|
||||
|
||||
let selectSQL = {
|
||||
var sql = "select * from \(name) where selected == true"
|
||||
@@ -32,9 +32,14 @@ struct SyncStatusTable {
|
||||
}()
|
||||
|
||||
guard let resultSet = database.executeQuery(selectSQL, withArgumentsIn: nil) else {
|
||||
database.rollback()
|
||||
return nil
|
||||
}
|
||||
|
||||
let statuses = resultSet.mapToSet(statusWithRow)
|
||||
|
||||
database.commit()
|
||||
|
||||
return statuses
|
||||
}
|
||||
|
||||
@@ -85,12 +90,11 @@ struct SyncStatusTable {
|
||||
|
||||
static func insertStatuses(_ statuses: Set<SyncStatus>, database: FMDatabase) {
|
||||
database.beginTransaction()
|
||||
defer {
|
||||
database.commit()
|
||||
}
|
||||
|
||||
let statusArray = statuses.map { $0.databaseDictionary() }
|
||||
database.insertRows(statusArray, insertType: .orReplace, tableName: name)
|
||||
|
||||
database.commit()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user