From cb96fe64ed02994f1fb996852e1623d75d066dff Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 8 Dec 2019 11:49:02 -0800 Subject: [PATCH 1/3] =?UTF-8?q?Fix=20bug=20where=20search=20indexing=20was?= =?UTF-8?q?n=E2=80=99t=20actually=20happening.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frameworks/ArticlesDatabase/ArticlesTable.swift | 1 + Frameworks/ArticlesDatabase/SearchTable.swift | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Frameworks/ArticlesDatabase/ArticlesTable.swift b/Frameworks/ArticlesDatabase/ArticlesTable.swift index bbdddfdac..864e55711 100644 --- a/Frameworks/ArticlesDatabase/ArticlesTable.swift +++ b/Frameworks/ArticlesDatabase/ArticlesTable.swift @@ -440,6 +440,7 @@ final class ArticlesTable: DatabaseTable { if articleIDs.isEmpty { return } + self.searchTable.ensureIndexedArticles(articleIDs, database) DispatchQueue.main.async { self.indexUnindexedArticles() diff --git a/Frameworks/ArticlesDatabase/SearchTable.swift b/Frameworks/ArticlesDatabase/SearchTable.swift index da0d35d2d..ad3412c03 100644 --- a/Frameworks/ArticlesDatabase/SearchTable.swift +++ b/Frameworks/ArticlesDatabase/SearchTable.swift @@ -77,12 +77,8 @@ final class SearchTable: DatabaseTable { self.ensureIndexedArticles(articleIDs, database) } } -} - -// MARK: - Private - -private extension SearchTable { + /// Add to, or update, the search index for articles with specified IDs. func ensureIndexedArticles(_ articleIDs: Set, _ database: FMDatabase) { guard let articlesTable = articlesTable else { return @@ -97,6 +93,11 @@ private extension SearchTable { let indexedArticles = articleSearchInfos.filter { $0.searchRowID != nil } updateIndexForArticles(indexedArticles, database) } +} + +// MARK: - Private + +private extension SearchTable { func performInitialIndexForArticles(_ articles: Set, _ database: FMDatabase) { articles.forEach { performInitialIndex($0, database) } From 6ee5622adc83615f807ca4de65ea6a01ddbc3cbd Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 8 Dec 2019 15:14:29 -0800 Subject: [PATCH 2/3] Bump build to 18. --- xcconfig/common/NetNewsWire_ios_target_common.xcconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xcconfig/common/NetNewsWire_ios_target_common.xcconfig b/xcconfig/common/NetNewsWire_ios_target_common.xcconfig index 4f3304fd8..ac97bad41 100644 --- a/xcconfig/common/NetNewsWire_ios_target_common.xcconfig +++ b/xcconfig/common/NetNewsWire_ios_target_common.xcconfig @@ -1,7 +1,7 @@ // High Level Settings common to both the iOS application and any extensions we bundle with it MARKETING_VERSION = 5.0 -CURRENT_PROJECT_VERSION = 17 +CURRENT_PROJECT_VERSION = 18 ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon From 03f95e4788533c3c0cb4d813dd0d42600b5f1f2a Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 8 Dec 2019 17:14:20 -0800 Subject: [PATCH 3/3] Make article indexing more efficient. --- Frameworks/ArticlesDatabase/ArticlesTable.swift | 12 ++---------- Frameworks/ArticlesDatabase/SearchTable.swift | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Frameworks/ArticlesDatabase/ArticlesTable.swift b/Frameworks/ArticlesDatabase/ArticlesTable.swift index 864e55711..ef98710d5 100644 --- a/Frameworks/ArticlesDatabase/ArticlesTable.swift +++ b/Frameworks/ArticlesDatabase/ArticlesTable.swift @@ -277,19 +277,11 @@ final class ArticlesTable: DatabaseTable { self.callUpdateArticlesCompletionBlock(newArticles, updatedArticles, completion) //7 // 8. Update search index. - var articlesToIndex = Set
() if let newArticles = newArticles { - articlesToIndex.formUnion(newArticles) + self.searchTable.indexNewArticles(newArticles, database) } if let updatedArticles = updatedArticles { - articlesToIndex.formUnion(updatedArticles) - } - let articleIDsToIndex = articlesToIndex.articleIDs() - if articleIDsToIndex.isEmpty { - return - } - DispatchQueue.main.async { - self.searchTable.ensureIndexedArticles(for: articleIDsToIndex) + self.searchTable.indexUpdatedArticles(updatedArticles, database) } } } diff --git a/Frameworks/ArticlesDatabase/SearchTable.swift b/Frameworks/ArticlesDatabase/SearchTable.swift index ad3412c03..77a83fc5e 100644 --- a/Frameworks/ArticlesDatabase/SearchTable.swift +++ b/Frameworks/ArticlesDatabase/SearchTable.swift @@ -45,6 +45,10 @@ final class ArticleSearchInfo: Hashable { self.searchRowID = searchRowID } + convenience init(article: Article) { + self.init(articleID: article.articleID, title: article.title, contentHTML: article.contentHTML, contentText: article.contentText, summary: article.summary, searchRowID: nil) + } + // MARK: Hashable public func hash(into hasher: inout Hasher) { @@ -93,6 +97,17 @@ final class SearchTable: DatabaseTable { let indexedArticles = articleSearchInfos.filter { $0.searchRowID != nil } updateIndexForArticles(indexedArticles, database) } + + /// Index new articles. + func indexNewArticles(_ articles: Set
, _ database: FMDatabase) { + let articleSearchInfos = Set(articles.map{ ArticleSearchInfo(article: $0) }) + performInitialIndexForArticles(articleSearchInfos, database) + } + + /// Index updated articles. + func indexUpdatedArticles(_ articles: Set
, _ database: FMDatabase) { + ensureIndexedArticles(articles.articleIDs(), database) + } } // MARK: - Private