mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-02-02 12:06:58 +01:00
Re add code and clean up
- Re add code reverted earlier - Clean up code that builds `authorsNames` based on model objects - Applied the right indentation
This commit is contained in:
parent
3e082f938a
commit
ddf9f41145
@ -145,19 +145,36 @@ final class ArticlesTable: DatabaseTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Fetching Articles for Indexer
|
// MARK: - Fetching Articles for Indexer
|
||||||
|
private func articleSearchInfosQuery(with placeholders: String) -> String {
|
||||||
|
return """
|
||||||
|
SELECT
|
||||||
|
art.articleID,
|
||||||
|
art.title,
|
||||||
|
art.contentHTML,
|
||||||
|
art.contentText,
|
||||||
|
art.summary,
|
||||||
|
art.searchRowID,
|
||||||
|
(SELECT GROUP_CONCAT(name, ' ')
|
||||||
|
FROM authorsLookup as autL
|
||||||
|
JOIN authors as aut ON autL.authorID = aut.authorID
|
||||||
|
WHERE art.articleID = autL.articleID
|
||||||
|
GROUP BY autl.articleID) as authors
|
||||||
|
FROM articles as art
|
||||||
|
WHERE articleID in \(placeholders);
|
||||||
|
"""
|
||||||
|
}
|
||||||
|
|
||||||
func fetchArticleSearchInfos(_ articleIDs: Set<String>, in database: FMDatabase) -> Set<ArticleSearchInfo>? {
|
func fetchArticleSearchInfos(_ articleIDs: Set<String>, in database: FMDatabase) -> Set<ArticleSearchInfo>? {
|
||||||
let parameters = articleIDs.map { $0 as AnyObject }
|
let parameters = articleIDs.map { $0 as AnyObject }
|
||||||
let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(articleIDs.count))!
|
let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(articleIDs.count))!
|
||||||
let sql = "select articleID, title, contentHTML, contentText, summary, searchRowID from articles where articleID in \(placeholders);";
|
if let resultSet = database.executeQuery(self.articleSearchInfosQuery(with: placeholders), withArgumentsIn: parameters) {
|
||||||
|
|
||||||
if let resultSet = database.executeQuery(sql, withArgumentsIn: parameters) {
|
|
||||||
return resultSet.mapToSet { (row) -> ArticleSearchInfo? in
|
return resultSet.mapToSet { (row) -> ArticleSearchInfo? in
|
||||||
let articleID = row.string(forColumn: DatabaseKey.articleID)!
|
let articleID = row.string(forColumn: DatabaseKey.articleID)!
|
||||||
let title = row.string(forColumn: DatabaseKey.title)
|
let title = row.string(forColumn: DatabaseKey.title)
|
||||||
let contentHTML = row.string(forColumn: DatabaseKey.contentHTML)
|
let contentHTML = row.string(forColumn: DatabaseKey.contentHTML)
|
||||||
let contentText = row.string(forColumn: DatabaseKey.contentText)
|
let contentText = row.string(forColumn: DatabaseKey.contentText)
|
||||||
let summary = row.string(forColumn: DatabaseKey.summary)
|
let summary = row.string(forColumn: DatabaseKey.summary)
|
||||||
|
let authorsNames = row.string(forColumn: DatabaseKey.authors)
|
||||||
|
|
||||||
let searchRowIDObject = row.object(forColumnName: DatabaseKey.searchRowID)
|
let searchRowIDObject = row.object(forColumnName: DatabaseKey.searchRowID)
|
||||||
var searchRowID: Int? = nil
|
var searchRowID: Int? = nil
|
||||||
@ -165,7 +182,7 @@ final class ArticlesTable: DatabaseTable {
|
|||||||
searchRowID = Int(row.longLongInt(forColumn: DatabaseKey.searchRowID))
|
searchRowID = Int(row.longLongInt(forColumn: DatabaseKey.searchRowID))
|
||||||
}
|
}
|
||||||
|
|
||||||
return ArticleSearchInfo(articleID: articleID, title: title, contentHTML: contentHTML, contentText: contentText, summary: summary, searchRowID: searchRowID)
|
return ArticleSearchInfo(articleID: articleID, title: title, contentHTML: contentHTML, contentText: contentText, summary: summary, authorsNames: authorsNames, searchRowID: searchRowID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -20,6 +20,7 @@ final class ArticleSearchInfo: Hashable {
|
|||||||
let contentHTML: String?
|
let contentHTML: String?
|
||||||
let contentText: String?
|
let contentText: String?
|
||||||
let summary: String?
|
let summary: String?
|
||||||
|
let authorsNames: String?
|
||||||
let searchRowID: Int?
|
let searchRowID: Int?
|
||||||
|
|
||||||
var preferredText: String {
|
var preferredText: String {
|
||||||
@ -43,9 +44,10 @@ final class ArticleSearchInfo: Hashable {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
init(articleID: String, title: String?, contentHTML: String?, contentText: String?, summary: String?, searchRowID: Int?) {
|
init(articleID: String, title: String?, contentHTML: String?, contentText: String?, summary: String?, authorsNames: String?, searchRowID: Int?) {
|
||||||
self.articleID = articleID
|
self.articleID = articleID
|
||||||
self.title = title
|
self.title = title
|
||||||
|
self.authorsNames = authorsNames
|
||||||
self.contentHTML = contentHTML
|
self.contentHTML = contentHTML
|
||||||
self.contentText = contentText
|
self.contentText = contentText
|
||||||
self.summary = summary
|
self.summary = summary
|
||||||
@ -53,8 +55,13 @@ final class ArticleSearchInfo: Hashable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
convenience init(article: Article) {
|
convenience init(article: Article) {
|
||||||
let authorsNames = article.authors?.map({ $0.name }).reduce("", { $0.appending("").appending($1 ?? "") }).collapsingWhitespace
|
let authorsNames: String?
|
||||||
self.init(articleID: article.articleID, title: article.title, authorsNames: authorsNames, contentHTML: article.contentHTML, contentText: article.contentText, summary: article.summary, searchRowID: nil)
|
if let authors = article.authors {
|
||||||
|
authorsNames = authors.compactMap({ $0.name }).joined(separator: " ")
|
||||||
|
} else {
|
||||||
|
authorsNames = nil
|
||||||
|
}
|
||||||
|
self.init(articleID: article.articleID, title: article.title, contentHTML: article.contentHTML, contentText: article.contentText, summary: article.summary, authorsNames: authorsNames, searchRowID: nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: Hashable
|
// MARK: Hashable
|
||||||
@ -66,7 +73,7 @@ final class ArticleSearchInfo: Hashable {
|
|||||||
// MARK: Equatable
|
// MARK: Equatable
|
||||||
|
|
||||||
static func == (lhs: ArticleSearchInfo, rhs: ArticleSearchInfo) -> Bool {
|
static func == (lhs: ArticleSearchInfo, rhs: ArticleSearchInfo) -> Bool {
|
||||||
return lhs.articleID == rhs.articleID && lhs.title == rhs.title && lhs.contentHTML == rhs.contentHTML && lhs.contentText == rhs.contentText && lhs.summary == rhs.summary && lhs.searchRowID == rhs.searchRowID
|
return lhs.articleID == rhs.articleID && lhs.title == rhs.title && lhs.contentHTML == rhs.contentHTML && lhs.contentText == rhs.contentText && lhs.summary == rhs.summary && lhs.authorsNames == rhs.authorsNames && lhs.searchRowID == rhs.searchRowID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user