Create statusWithRow(_ row: FMResultSet, articleID: String) — it allows us to avoid pulling articleID from the row twice every time we’re creating a DatabaseArticle.
This commit is contained in:
parent
d7b45a1413
commit
2b491217f3
|
@ -475,16 +475,15 @@ private extension ArticlesTable {
|
||||||
func makeDatabaseArticles(with resultSet: FMResultSet) -> Set<DatabaseArticle> {
|
func makeDatabaseArticles(with resultSet: FMResultSet) -> Set<DatabaseArticle> {
|
||||||
let articles = resultSet.mapToSet { (row) -> DatabaseArticle? in
|
let articles = resultSet.mapToSet { (row) -> DatabaseArticle? in
|
||||||
|
|
||||||
// The resultSet is a result of a JOIN query with the statuses table,
|
guard let articleID = row.string(forColumn: DatabaseKey.articleID) else {
|
||||||
// so we can get the statuses at the same time and avoid additional database lookups.
|
assertionFailure("Expected articleID.")
|
||||||
|
|
||||||
guard let status = statusesTable.statusWithRow(resultSet) else {
|
|
||||||
assertionFailure("Expected status.")
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
guard let articleID = row.string(forColumn: DatabaseKey.articleID) else {
|
// The resultSet is a result of a JOIN query with the statuses table,
|
||||||
assertionFailure("Expected articleID.")
|
// so we can get the statuses at the same time and avoid additional database lookups.
|
||||||
|
guard let status = statusesTable.statusWithRow(resultSet, articleID: articleID) else {
|
||||||
|
assertionFailure("Expected status.")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
guard let feedID = row.string(forColumn: DatabaseKey.feedID) else {
|
guard let feedID = row.string(forColumn: DatabaseKey.feedID) else {
|
||||||
|
|
|
@ -105,6 +105,10 @@ final class StatusesTable: DatabaseTable {
|
||||||
guard let articleID = row.string(forColumn: DatabaseKey.articleID) else {
|
guard let articleID = row.string(forColumn: DatabaseKey.articleID) else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
return statusWithRow(row, articleID: articleID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func statusWithRow(_ row: FMResultSet, articleID: String) ->ArticleStatus? {
|
||||||
if let cachedStatus = cache[articleID] {
|
if let cachedStatus = cache[articleID] {
|
||||||
return cachedStatus
|
return cachedStatus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue