Fix some build errors in Database.framework.
This commit is contained in:
parent
8155aa4f5c
commit
07a44f7af0
@ -109,16 +109,15 @@ final class ArticlesTable: DatabaseTable {
|
|||||||
let fetchedArticles = self.fetchArticlesForFeedID(feedID, withLimits: false, database: database) //3
|
let fetchedArticles = self.fetchArticlesForFeedID(feedID, withLimits: false, database: database) //3
|
||||||
let fetchedArticlesDictionary = fetchedArticles.dictionary()
|
let fetchedArticlesDictionary = fetchedArticles.dictionary()
|
||||||
|
|
||||||
let incomingArticles = Article.articlesWithParsedItems(filteredParsedItems, accountID, feedID) //4
|
let incomingArticles = Article.articlesWithParsedItems(filteredParsedItems, self.accountID, feedID) //4
|
||||||
let incomingArticlesDictionary = incomingArticles.dictionary()
|
|
||||||
|
|
||||||
let newArticles = Set(incomingArticles.filter { fetchedArticles[$0.articleID] == nil }) //5
|
let newArticles = Set(incomingArticles.filter { fetchedArticlesDictionary[$0.articleID] == nil }) //5
|
||||||
if !newArticles.isEmpty {
|
if !newArticles.isEmpty {
|
||||||
saveNewArticles(newArticles, database)
|
self.saveNewArticles(newArticles, database)
|
||||||
}
|
}
|
||||||
|
|
||||||
let updatedArticles = incomingArticles.filter{ (incomingArticle) -> Bool in //6
|
let updatedArticles = incomingArticles.filter{ (incomingArticle) -> Bool in //6
|
||||||
if let existingArticle = fetchedArticles[incomingArticle.articleID] {
|
if let existingArticle = fetchedArticlesDictionary[incomingArticle.articleID] {
|
||||||
if existingArticle != incomingArticle {
|
if existingArticle != incomingArticle {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -126,7 +125,7 @@ final class ArticlesTable: DatabaseTable {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if !updatedArticles.isEmpty {
|
if !updatedArticles.isEmpty {
|
||||||
saveUpdatedArticles(Set(updatedArticles), fetchedArticlesDictionary, database)
|
self.saveUpdatedArticles(Set(updatedArticles), fetchedArticlesDictionary, database)
|
||||||
}
|
}
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
@ -161,28 +160,28 @@ final class ArticlesTable: DatabaseTable {
|
|||||||
|
|
||||||
// Sets flag in both memory and in database.
|
// Sets flag in both memory and in database.
|
||||||
|
|
||||||
let articleIDs = articles.flatMap { (article) -> String? in
|
// let articleIDs = articles.flatMap { (article) -> String? in
|
||||||
|
//
|
||||||
guard let status = article.status else {
|
// guard let status = article.status else {
|
||||||
assertionFailure("Each article must have a status.")
|
// assertionFailure("Each article must have a status.")
|
||||||
return nil
|
// return nil
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if status.boolStatus(forKey: statusKey) == flag {
|
// if status.boolStatus(forKey: statusKey) == flag {
|
||||||
return nil
|
// return nil
|
||||||
}
|
// }
|
||||||
status.setBoolStatus(flag, forKey: statusKey)
|
// status.setBoolStatus(flag, forKey: statusKey)
|
||||||
return article.articleID
|
// return article.articleID
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
if articleIDs.isEmpty {
|
// if articleIDs.isEmpty {
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
// TODO: statusesTable needs to cache status changes.
|
// // TODO: statusesTable needs to cache status changes.
|
||||||
queue.update { (database) in
|
// queue.update { (database) in
|
||||||
self.statusesTable.markArticleIDs(Set(articleIDs), statusKey, flag, database)
|
// 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)
|
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<Article> {
|
func articlesWithSQL(_ sql: String, _ parameters: [AnyObject], _ database: FMDatabase) -> Set<Article> {
|
||||||
@ -288,7 +287,7 @@ private extension ArticlesTable {
|
|||||||
|
|
||||||
// MARK: Update Existing Articles
|
// MARK: Update Existing Articles
|
||||||
|
|
||||||
func articlesWithRelatedObjectChanges(_ comparisonKeyPath: KeyPath<Article, Set<AnyHashable>>, _ updatedArticles: Set<Article>, _ fetchedArticles: [String: Article]) -> Set<Article> {
|
func articlesWithRelatedObjectChanges<T>(_ comparisonKeyPath: KeyPath<Article, Set<T>?>, _ updatedArticles: Set<Article>, _ fetchedArticles: [String: Article]) -> Set<Article> {
|
||||||
|
|
||||||
return updatedArticles.filter{ (updatedArticle) -> Bool in
|
return updatedArticles.filter{ (updatedArticle) -> Bool in
|
||||||
if let fetchedArticle = fetchedArticles[updatedArticle.articleID] {
|
if let fetchedArticle = fetchedArticles[updatedArticle.articleID] {
|
||||||
@ -299,7 +298,7 @@ private extension ArticlesTable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func updateRelatedObjects(_ comparisonKeyPath: KeyPath<Article, Set<AnyHashable>>, _ updatedArticles: Set<Article>, _ fetchedArticles: [String: Article], _ lookupTable: DatabaseLookupTable, _ database: FMDatabase) {
|
func updateRelatedObjects<T>(_ comparisonKeyPath: KeyPath<Article, Set<T>?>, _ updatedArticles: Set<Article>, _ fetchedArticles: [String: Article], _ lookupTable: DatabaseLookupTable, _ database: FMDatabase) {
|
||||||
|
|
||||||
let articlesWithChanges = articlesWithRelatedObjectChanges(comparisonKeyPath, updatedArticles, fetchedArticles)
|
let articlesWithChanges = articlesWithRelatedObjectChanges(comparisonKeyPath, updatedArticles, fetchedArticles)
|
||||||
if !articlesWithChanges.isEmpty {
|
if !articlesWithChanges.isEmpty {
|
||||||
|
@ -42,9 +42,8 @@ extension Article {
|
|||||||
|
|
||||||
let authors = Author.authorsWithParsedAuthors(parsedItem.authors)
|
let authors = Author.authorsWithParsedAuthors(parsedItem.authors)
|
||||||
let attachments = Attachment.attachmentsWithParsedAttachments(parsedItem.attachments)
|
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 {
|
func databaseDictionary() -> NSDictionary {
|
||||||
|
@ -29,14 +29,10 @@ extension Attachment {
|
|||||||
|
|
||||||
init?(parsedAttachment: ParsedAttachment) {
|
init?(parsedAttachment: ParsedAttachment) {
|
||||||
|
|
||||||
guard let url = parsedAttachment.url else {
|
self.init(attachmentID: nil, url: parsedAttachment.url, mimeType: parsedAttachment.mimeType, title: parsedAttachment.title, sizeInBytes: parsedAttachment.sizeInBytes, durationInSeconds: parsedAttachment.durationInSeconds)
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
self.init(attachmentID: nil, url: url, mimeType: parsedAttachment.mimeType, title: parsedAttachment.title, sizeInBytes: parsedAttachment.sizeInBytes, durationInSeconds: parsedAttachment.durationInSeconds)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static func attachmentsWithParsedAttachments(_ parsedAttachments: [ParsedAttachment]?) -> Set<Attachment>? {
|
static func attachmentsWithParsedAttachments(_ parsedAttachments: Set<ParsedAttachment>?) -> Set<Attachment>? {
|
||||||
|
|
||||||
guard let parsedAttachments = parsedAttachments else {
|
guard let parsedAttachments = parsedAttachments else {
|
||||||
return nil
|
return nil
|
||||||
|
@ -13,7 +13,7 @@ import RSParser
|
|||||||
|
|
||||||
extension Author {
|
extension Author {
|
||||||
|
|
||||||
static func authorsWithParsedAuthors(_ parsedAuthors: [ParsedAuthor]?) -> Set<Author>? {
|
static func authorsWithParsedAuthors(_ parsedAuthors: Set<ParsedAuthor>?) -> Set<Author>? {
|
||||||
|
|
||||||
assert(!Thread.isMainThread)
|
assert(!Thread.isMainThread)
|
||||||
|
|
||||||
|
@ -21,11 +21,4 @@ extension String: DatabaseObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func tagSetWithParsedTags(_ parsedTags: [String]?) -> Set<String>? {
|
|
||||||
|
|
||||||
guard let parsedTags = parsedTags, !parsedTags.isEmpty else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return Set(parsedTags)
|
|
||||||
}
|
|
||||||
|
@ -55,7 +55,7 @@ final class StatusesTable: DatabaseTable {
|
|||||||
|
|
||||||
let articleIDsNeedingStatus = self.articleIDsWithNoCachedStatus(articleIDs)
|
let articleIDsNeedingStatus = self.articleIDsWithNoCachedStatus(articleIDs)
|
||||||
if articleIDsNeedingStatus.isEmpty {
|
if articleIDsNeedingStatus.isEmpty {
|
||||||
completion(statusesDictionary(articleIDs))
|
completion(self.statusesDictionary(articleIDs))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user