Remove cache from Author since it’s now in AuthorsTable.
This commit is contained in:
parent
b235701015
commit
d284bf3757
@ -24,24 +24,6 @@ extension Author {
|
||||
let authors = Set(parsedAuthors.flatMap { authorWithParsedAuthor($0) })
|
||||
return authors.isEmpty ? nil : authors
|
||||
}
|
||||
|
||||
static func authorWithRow(_ row: FMResultSet) -> Author? {
|
||||
|
||||
guard let authorID = row.string(forColumn: DatabaseKey.authorID) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
if let cachedAuthor = cachedAuthor(authorID) {
|
||||
return cachedAuthor
|
||||
}
|
||||
|
||||
guard let author = Author(authorID: authorID, row: row) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
cacheAuthor(author)
|
||||
return author
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - DatabaseObject
|
||||
@ -59,8 +41,9 @@ extension Author: DatabaseObject {
|
||||
|
||||
private extension Author {
|
||||
|
||||
init?(authorID: String, row: FMResultSet) {
|
||||
|
||||
init?(row: FMResultSet) {
|
||||
|
||||
let authorID = row.string(forColumn: DatabaseKey.authorID)
|
||||
let name = row.string(forColumn: DatabaseKey.name)
|
||||
let url = row.string(forColumn: DatabaseKey.url)
|
||||
let avatarURL = row.string(forColumn: DatabaseKey.avatarURL)
|
||||
@ -73,36 +56,5 @@ private extension Author {
|
||||
|
||||
self.init(authorID: nil, name: parsedAuthor.name, url: parsedAuthor.url, avatarURL: parsedAuthor.avatarURL, emailAddress: parsedAuthor.emailAddress)
|
||||
}
|
||||
|
||||
static func authorWithParsedAuthor(_ parsedAuthor: ParsedAuthor) -> Author? {
|
||||
|
||||
if let author = Author(parsedAuthor: parsedAuthor) {
|
||||
if let authorFromCache = cachedAuthor(author.authorID) {
|
||||
return authorFromCache
|
||||
}
|
||||
cacheAuthor(author)
|
||||
return author
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// The authorCache isn’t because we need uniquing — it’s just to cut down
|
||||
// on the number of Author instances, since they would be frequently duplicated.
|
||||
// (That is, a given feed might have 10 or 20 or whatever of the same Author.)
|
||||
|
||||
private static var authorCache = [String: Author]() //queue-only
|
||||
|
||||
static func cachedAuthor(_ authorID: String) -> Author? {
|
||||
|
||||
assert(!Thread.isMainThread)
|
||||
return authorCache[authorID]
|
||||
}
|
||||
|
||||
static func cacheAuthor(_ author: Author) {
|
||||
|
||||
assert(!Thread.isMainThread)
|
||||
authorCache[author.authorID] = author
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user