Make article indexing more efficient.
This commit is contained in:
parent
6ee5622adc
commit
03f95e4788
|
@ -277,19 +277,11 @@ final class ArticlesTable: DatabaseTable {
|
||||||
self.callUpdateArticlesCompletionBlock(newArticles, updatedArticles, completion) //7
|
self.callUpdateArticlesCompletionBlock(newArticles, updatedArticles, completion) //7
|
||||||
|
|
||||||
// 8. Update search index.
|
// 8. Update search index.
|
||||||
var articlesToIndex = Set<Article>()
|
|
||||||
if let newArticles = newArticles {
|
if let newArticles = newArticles {
|
||||||
articlesToIndex.formUnion(newArticles)
|
self.searchTable.indexNewArticles(newArticles, database)
|
||||||
}
|
}
|
||||||
if let updatedArticles = updatedArticles {
|
if let updatedArticles = updatedArticles {
|
||||||
articlesToIndex.formUnion(updatedArticles)
|
self.searchTable.indexUpdatedArticles(updatedArticles, database)
|
||||||
}
|
|
||||||
let articleIDsToIndex = articlesToIndex.articleIDs()
|
|
||||||
if articleIDsToIndex.isEmpty {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
DispatchQueue.main.async {
|
|
||||||
self.searchTable.ensureIndexedArticles(for: articleIDsToIndex)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,10 @@ final class ArticleSearchInfo: Hashable {
|
||||||
self.searchRowID = searchRowID
|
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
|
// MARK: Hashable
|
||||||
|
|
||||||
public func hash(into hasher: inout Hasher) {
|
public func hash(into hasher: inout Hasher) {
|
||||||
|
@ -93,6 +97,17 @@ final class SearchTable: DatabaseTable {
|
||||||
let indexedArticles = articleSearchInfos.filter { $0.searchRowID != nil }
|
let indexedArticles = articleSearchInfos.filter { $0.searchRowID != nil }
|
||||||
updateIndexForArticles(indexedArticles, database)
|
updateIndexForArticles(indexedArticles, database)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Index new articles.
|
||||||
|
func indexNewArticles(_ articles: Set<Article>, _ database: FMDatabase) {
|
||||||
|
let articleSearchInfos = Set(articles.map{ ArticleSearchInfo(article: $0) })
|
||||||
|
performInitialIndexForArticles(articleSearchInfos, database)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Index updated articles.
|
||||||
|
func indexUpdatedArticles(_ articles: Set<Article>, _ database: FMDatabase) {
|
||||||
|
ensureIndexedArticles(articles.articleIDs(), database)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Private
|
// MARK: - Private
|
||||||
|
|
Loading…
Reference in New Issue