From 7f82f9d6077eba37a7f8753b8c1d345aed413181 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Fri, 8 Feb 2019 20:41:46 -0800 Subject: [PATCH] =?UTF-8?q?Fix=20a=20bug=20where=20articles=20with=20chang?= =?UTF-8?q?ed=20dates=20wouldn=E2=80=99t=20update=20in=20the=20database.?= =?UTF-8?q?=20Make=20the=20code=20a=20bit=20more=20clear,=20too.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/Article+Database.swift | 47 ++++++++----------- 1 file changed, 19 insertions(+), 28 deletions(-) diff --git a/Frameworks/ArticlesDatabase/Extensions/Article+Database.swift b/Frameworks/ArticlesDatabase/Extensions/Article+Database.swift index 6a6217bd7..17914c39b 100644 --- a/Frameworks/ArticlesDatabase/Extensions/Article+Database.swift +++ b/Frameworks/ArticlesDatabase/Extensions/Article+Database.swift @@ -33,48 +33,39 @@ extension Article { } } - func changesFrom(_ otherArticle: Article) -> NSDictionary? { - - if self == otherArticle { + func changesFrom(_ existingArticle: Article) -> NSDictionary? { + if self == existingArticle { return nil } let d = NSMutableDictionary() - if uniqueID != otherArticle.uniqueID { - // This should be super-rare, if ever. - if !otherArticle.uniqueID.isEmpty { - d[DatabaseKey.uniqueID] = otherArticle.uniqueID - } + if uniqueID != existingArticle.uniqueID { + d[DatabaseKey.uniqueID] = uniqueID } - - addPossibleStringChangeWithKeyPath(\Article.title, otherArticle, DatabaseKey.title, d) - addPossibleStringChangeWithKeyPath(\Article.contentHTML, otherArticle, DatabaseKey.contentHTML, d) - addPossibleStringChangeWithKeyPath(\Article.contentText, otherArticle, DatabaseKey.contentText, d) - addPossibleStringChangeWithKeyPath(\Article.url, otherArticle, DatabaseKey.url, d) - addPossibleStringChangeWithKeyPath(\Article.externalURL, otherArticle, DatabaseKey.externalURL, d) - addPossibleStringChangeWithKeyPath(\Article.summary, otherArticle, DatabaseKey.summary, d) - addPossibleStringChangeWithKeyPath(\Article.imageURL, otherArticle, DatabaseKey.imageURL, d) - addPossibleStringChangeWithKeyPath(\Article.bannerImageURL, otherArticle, DatabaseKey.bannerImageURL, d) + + addPossibleStringChangeWithKeyPath(\Article.title, existingArticle, DatabaseKey.title, d) + addPossibleStringChangeWithKeyPath(\Article.contentHTML, existingArticle, DatabaseKey.contentHTML, d) + addPossibleStringChangeWithKeyPath(\Article.contentText, existingArticle, DatabaseKey.contentText, d) + addPossibleStringChangeWithKeyPath(\Article.url, existingArticle, DatabaseKey.url, d) + addPossibleStringChangeWithKeyPath(\Article.externalURL, existingArticle, DatabaseKey.externalURL, d) + addPossibleStringChangeWithKeyPath(\Article.summary, existingArticle, DatabaseKey.summary, d) + addPossibleStringChangeWithKeyPath(\Article.imageURL, existingArticle, DatabaseKey.imageURL, d) + addPossibleStringChangeWithKeyPath(\Article.bannerImageURL, existingArticle, DatabaseKey.bannerImageURL, d) // If updated versions of dates are nil, and we have existing dates, keep the existing dates. // This is data that’s good to have, and it’s likely that a feed removing dates is doing so in error. - - if datePublished != otherArticle.datePublished { - if let updatedDatePublished = otherArticle.datePublished { + if datePublished != existingArticle.datePublished { + if let updatedDatePublished = datePublished { d[DatabaseKey.datePublished] = updatedDatePublished } } - if dateModified != otherArticle.dateModified { - if let updatedDateModified = otherArticle.dateModified { + if dateModified != existingArticle.dateModified { + if let updatedDateModified = dateModified { d[DatabaseKey.dateModified] = updatedDateModified } } - - if d.count < 1 { - return nil - } - - return d + + return d.count < 1 ? nil : d } static func articlesWithParsedItems(_ parsedItems: Set, _ accountID: String, _ feedID: String, _ statusesDictionary: [String: ArticleStatus]) -> Set
{