From d284bf37572e4195a6328e05ab5e0f3629114b81 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Tue, 12 Sep 2017 22:27:36 -0700 Subject: [PATCH] =?UTF-8?q?Remove=20cache=20from=20Author=20since=20it?= =?UTF-8?q?=E2=80=99s=20now=20in=20AuthorsTable.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Database/Extensions/Author+Database.swift | 54 ++----------------- 1 file changed, 3 insertions(+), 51 deletions(-) diff --git a/Frameworks/Database/Extensions/Author+Database.swift b/Frameworks/Database/Extensions/Author+Database.swift index cfe414a15..5ecfcec42 100644 --- a/Frameworks/Database/Extensions/Author+Database.swift +++ b/Frameworks/Database/Extensions/Author+Database.swift @@ -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 - } }