diff --git a/Frameworks/Database/AttachmentsTable.swift b/Frameworks/Database/AttachmentsTable.swift index ca13cf7fb..122d06aef 100644 --- a/Frameworks/Database/AttachmentsTable.swift +++ b/Frameworks/Database/AttachmentsTable.swift @@ -24,38 +24,11 @@ final class AttachmentsTable: DatabaseRelatedObjectsTable { // MARK: DatabaseRelatedObjectsTable func objectWithRow(_ row: FMResultSet) -> DatabaseObject? { - - if let attachment = attachmentWithRow(row) { + + if let attachment = Attachment(row: row) { return attachment as DatabaseObject } return nil } - - func save(_ objects: [DatabaseObject], in database: FMDatabase) { - - let attachments = objects.map { $0 as! Attachment } - - // Attachments in cache must already exist in database. Filter them out. - let attachmentsToSave = Set(attachments.filter { (attachment) -> Bool in - if let _ = cache[attachment.attachmentID] { - return false - } - return true - }) - - cache.add(attachmentsToSave.databaseObjects()) - - insertRows(attachmentsToSave.databaseDictionaries(), insertType: .orIgnore, in: database) - } -} - -private extension AttachmentsTable { - - func attachmentWithRow(_ row: FMResultSet) -> Attachment? { - - // attachmentID is non-null in database schema. - let attachmentID = row.string(forColumn: DatabaseKey.attachmentID)! - return Attachment(attachmentID: attachmentID, row: row) - } } diff --git a/Frameworks/Database/Extensions/Attachment+Database.swift b/Frameworks/Database/Extensions/Attachment+Database.swift index d70751982..b84f0aae8 100644 --- a/Frameworks/Database/Extensions/Attachment+Database.swift +++ b/Frameworks/Database/Extensions/Attachment+Database.swift @@ -13,12 +13,13 @@ import RSParser extension Attachment { - init?(attachmentID: String, row: FMResultSet) { + init?(row: FMResultSet) { guard let url = row.string(forColumn: DatabaseKey.url) else { return nil } + let attachmentID = row.string(forColumn: DatabaseKey.attachmentID) let mimeType = row.string(forColumn: DatabaseKey.mimeType) let title = row.string(forColumn: DatabaseKey.title) let sizeInBytes = optionalIntForColumn(row, DatabaseKey.sizeInBytes) diff --git a/Frameworks/Database/StatusesTable.swift b/Frameworks/Database/StatusesTable.swift index c7b1e4c30..c232653b8 100644 --- a/Frameworks/Database/StatusesTable.swift +++ b/Frameworks/Database/StatusesTable.swift @@ -94,8 +94,9 @@ final class StatusesTable: DatabaseTable { if status.boolStatus(forKey: statusKey) == flag { continue } - status.setBoolStatus(flag, forKey: statusKey) - updatedStatuses.insert(status) + var statusCopy = status + statusCopy.setBoolStatus(flag, forKey: statusKey) + updatedStatuses.insert(statusCopy) } if updatedStatuses.isEmpty {