Make AttachmentsTable use default implementation of save.
This commit is contained in:
parent
ea6d8b0bb8
commit
1f35892791
|
@ -25,37 +25,10 @@ final class AttachmentsTable: 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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue