diff --git a/Frameworks/Database/ArticlesTable.swift b/Frameworks/Database/ArticlesTable.swift index fd4dcbea9..c8521b273 100644 --- a/Frameworks/Database/ArticlesTable.swift +++ b/Frameworks/Database/ArticlesTable.swift @@ -109,16 +109,15 @@ final class ArticlesTable: DatabaseTable { let fetchedArticles = self.fetchArticlesForFeedID(feedID, withLimits: false, database: database) //3 let fetchedArticlesDictionary = fetchedArticles.dictionary() - let incomingArticles = Article.articlesWithParsedItems(filteredParsedItems, accountID, feedID) //4 - let incomingArticlesDictionary = incomingArticles.dictionary() + let incomingArticles = Article.articlesWithParsedItems(filteredParsedItems, self.accountID, feedID) //4 - let newArticles = Set(incomingArticles.filter { fetchedArticles[$0.articleID] == nil }) //5 + let newArticles = Set(incomingArticles.filter { fetchedArticlesDictionary[$0.articleID] == nil }) //5 if !newArticles.isEmpty { - saveNewArticles(newArticles, database) + self.saveNewArticles(newArticles, database) } let updatedArticles = incomingArticles.filter{ (incomingArticle) -> Bool in //6 - if let existingArticle = fetchedArticles[incomingArticle.articleID] { + if let existingArticle = fetchedArticlesDictionary[incomingArticle.articleID] { if existingArticle != incomingArticle { return true } @@ -126,7 +125,7 @@ final class ArticlesTable: DatabaseTable { return false } if !updatedArticles.isEmpty { - saveUpdatedArticles(Set(updatedArticles), fetchedArticlesDictionary, database) + self.saveUpdatedArticles(Set(updatedArticles), fetchedArticlesDictionary, database) } DispatchQueue.main.async { @@ -161,28 +160,28 @@ final class ArticlesTable: DatabaseTable { // Sets flag in both memory and in database. - let articleIDs = articles.flatMap { (article) -> String? in - - guard let status = article.status else { - assertionFailure("Each article must have a status.") - return nil - } - - if status.boolStatus(forKey: statusKey) == flag { - return nil - } - status.setBoolStatus(flag, forKey: statusKey) - return article.articleID - } - - if articleIDs.isEmpty { - return - } - - // TODO: statusesTable needs to cache status changes. - queue.update { (database) in - self.statusesTable.markArticleIDs(Set(articleIDs), statusKey, flag, database) - } +// let articleIDs = articles.flatMap { (article) -> String? in +// +// guard let status = article.status else { +// assertionFailure("Each article must have a status.") +// return nil +// } +// +// if status.boolStatus(forKey: statusKey) == flag { +// return nil +// } +// status.setBoolStatus(flag, forKey: statusKey) +// return article.articleID +// } +// +// if articleIDs.isEmpty { +// return +// } +// +// // TODO: statusesTable needs to cache status changes. +// queue.update { (database) in +// self.statusesTable.markArticleIDs(Set(articleIDs), statusKey, flag, database) +// } } } @@ -256,7 +255,7 @@ private extension ArticlesTable { articles = self.fetchArticlesWithWhereClause(database, whereClause: whereClause, parameters: parameters, withLimits: true) } - return articleCache.uniquedArticles(articles) + return articles } func articlesWithSQL(_ sql: String, _ parameters: [AnyObject], _ database: FMDatabase) -> Set
{ @@ -288,7 +287,7 @@ private extension ArticlesTable { // MARK: Update Existing Articles - func articlesWithRelatedObjectChanges(_ comparisonKeyPath: KeyPath>, _ updatedArticles: Set
, _ fetchedArticles: [String: Article]) -> Set
{ + func articlesWithRelatedObjectChanges(_ comparisonKeyPath: KeyPath?>, _ updatedArticles: Set
, _ fetchedArticles: [String: Article]) -> Set
{ return updatedArticles.filter{ (updatedArticle) -> Bool in if let fetchedArticle = fetchedArticles[updatedArticle.articleID] { @@ -299,7 +298,7 @@ private extension ArticlesTable { } } - func updateRelatedObjects(_ comparisonKeyPath: KeyPath>, _ updatedArticles: Set
, _ fetchedArticles: [String: Article], _ lookupTable: DatabaseLookupTable, _ database: FMDatabase) { + func updateRelatedObjects(_ comparisonKeyPath: KeyPath?>, _ updatedArticles: Set
, _ fetchedArticles: [String: Article], _ lookupTable: DatabaseLookupTable, _ database: FMDatabase) { let articlesWithChanges = articlesWithRelatedObjectChanges(comparisonKeyPath, updatedArticles, fetchedArticles) if !articlesWithChanges.isEmpty { diff --git a/Frameworks/Database/Extensions/Article+Database.swift b/Frameworks/Database/Extensions/Article+Database.swift index 6db9acb10..b10b34aeb 100644 --- a/Frameworks/Database/Extensions/Article+Database.swift +++ b/Frameworks/Database/Extensions/Article+Database.swift @@ -42,9 +42,8 @@ extension Article { let authors = Author.authorsWithParsedAuthors(parsedItem.authors) let attachments = Attachment.attachmentsWithParsedAttachments(parsedItem.attachments) - let tags = tagSetWithParsedTags(parsedItem.tags) - self.init(accountID: accountID, articleID: parsedItem.syncServiceID, feedID: feedID, uniqueID: parsedItem.uniqueID, title: parsedItem.title, contentHTML: parsedItem.contentHTML, contentText: parsedItem.contentText, url: parsedItem.url, externalURL: parsedItem.externalURL, summary: parsedItem.summary, imageURL: parsedItem.imageURL, bannerImageURL: parsedItem.bannerImageURL, datePublished: parsedItem.datePublished, dateModified: parsedItem.dateModified, authors: authors, tags: tags, attachments: attachments, accountInfo: nil) + self.init(accountID: accountID, articleID: parsedItem.syncServiceID, feedID: feedID, uniqueID: parsedItem.uniqueID, title: parsedItem.title, contentHTML: parsedItem.contentHTML, contentText: parsedItem.contentText, url: parsedItem.url, externalURL: parsedItem.externalURL, summary: parsedItem.summary, imageURL: parsedItem.imageURL, bannerImageURL: parsedItem.bannerImageURL, datePublished: parsedItem.datePublished, dateModified: parsedItem.dateModified, authors: authors, tags: parsedItem.tags, attachments: attachments, accountInfo: nil) } func databaseDictionary() -> NSDictionary { diff --git a/Frameworks/Database/Extensions/Attachment+Database.swift b/Frameworks/Database/Extensions/Attachment+Database.swift index 796514d58..b9d977bec 100644 --- a/Frameworks/Database/Extensions/Attachment+Database.swift +++ b/Frameworks/Database/Extensions/Attachment+Database.swift @@ -29,14 +29,10 @@ extension Attachment { init?(parsedAttachment: ParsedAttachment) { - guard let url = parsedAttachment.url else { - return nil - } - - self.init(attachmentID: nil, url: url, mimeType: parsedAttachment.mimeType, title: parsedAttachment.title, sizeInBytes: parsedAttachment.sizeInBytes, durationInSeconds: parsedAttachment.durationInSeconds) + self.init(attachmentID: nil, url: parsedAttachment.url, mimeType: parsedAttachment.mimeType, title: parsedAttachment.title, sizeInBytes: parsedAttachment.sizeInBytes, durationInSeconds: parsedAttachment.durationInSeconds) } - static func attachmentsWithParsedAttachments(_ parsedAttachments: [ParsedAttachment]?) -> Set? { + static func attachmentsWithParsedAttachments(_ parsedAttachments: Set?) -> Set? { guard let parsedAttachments = parsedAttachments else { return nil diff --git a/Frameworks/Database/Extensions/Author+Database.swift b/Frameworks/Database/Extensions/Author+Database.swift index 452d000ad..cfe414a15 100644 --- a/Frameworks/Database/Extensions/Author+Database.swift +++ b/Frameworks/Database/Extensions/Author+Database.swift @@ -13,7 +13,7 @@ import RSParser extension Author { - static func authorsWithParsedAuthors(_ parsedAuthors: [ParsedAuthor]?) -> Set? { + static func authorsWithParsedAuthors(_ parsedAuthors: Set?) -> Set? { assert(!Thread.isMainThread) diff --git a/Frameworks/Database/Extensions/String+Database.swift b/Frameworks/Database/Extensions/String+Database.swift index ae5fc9d6c..1711d4a40 100644 --- a/Frameworks/Database/Extensions/String+Database.swift +++ b/Frameworks/Database/Extensions/String+Database.swift @@ -21,11 +21,4 @@ extension String: DatabaseObject { } } -func tagSetWithParsedTags(_ parsedTags: [String]?) -> Set? { - guard let parsedTags = parsedTags, !parsedTags.isEmpty else { - return nil - } - - return Set(parsedTags) -} diff --git a/Frameworks/Database/StatusesTable.swift b/Frameworks/Database/StatusesTable.swift index 1f59dbffd..6a8c15157 100644 --- a/Frameworks/Database/StatusesTable.swift +++ b/Frameworks/Database/StatusesTable.swift @@ -55,7 +55,7 @@ final class StatusesTable: DatabaseTable { let articleIDsNeedingStatus = self.articleIDsWithNoCachedStatus(articleIDs) if articleIDsNeedingStatus.isEmpty { - completion(statusesDictionary(articleIDs)) + completion(self.statusesDictionary(articleIDs)) return }