Start work on Author management.
This commit is contained in:
parent
e3b8e6833b
commit
13f8c4f9b1
|
@ -12,7 +12,7 @@ public final class Article: Hashable {
|
|||
|
||||
weak var account: Account?
|
||||
|
||||
public let articleID: String // Unique per database
|
||||
public let databaseID: String
|
||||
public let feedID: String // Likely a URL, but not necessarily
|
||||
public let uniqueID: String // Unique per feed (RSS guid, for example)
|
||||
public var title: String?
|
||||
|
@ -39,10 +39,10 @@ public final class Article: Hashable {
|
|||
}
|
||||
}
|
||||
|
||||
init(account: Account, articleID: String, feedID: String, uniqueID: String, title: String?, contentHTML: String?, contentText: String?, url: String?, externalURL: String?, summary: String?, imageURL: String?, bannerImageURL: String?, datePublished: Date?, dateModified: Date?, authors: [Author]?, tags: Set<String>?, attachments: [Attachment]?, accountInfo: AccountInfo?) {
|
||||
init(account: Account, databaseID: String, feedID: String, uniqueID: String, title: String?, contentHTML: String?, contentText: String?, url: String?, externalURL: String?, summary: String?, imageURL: String?, bannerImageURL: String?, datePublished: Date?, dateModified: Date?, authors: [Author]?, tags: Set<String>?, attachments: [Attachment]?, accountInfo: AccountInfo?) {
|
||||
|
||||
self.account = account
|
||||
self.articleID = articleID
|
||||
self.databaseID = databaseID
|
||||
self.feedID = feedID
|
||||
self.uniqueID = uniqueID
|
||||
self.title = title
|
||||
|
|
|
@ -7,16 +7,18 @@
|
|||
//
|
||||
|
||||
import Foundation
|
||||
import RSCore
|
||||
|
||||
public struct Author: Hashable {
|
||||
|
||||
public let databaseID: String // calculated
|
||||
public let name: String?
|
||||
public let url: String?
|
||||
public let avatarURL: String?
|
||||
public let emailAddress: String?
|
||||
public let hashValue: Int
|
||||
|
||||
public init?(name: String?, url: String?, avatarURL: String?, emailAddress: String?) {
|
||||
public init?(databaseID: String?, name: String?, url: String?, avatarURL: String?, emailAddress: String?) {
|
||||
|
||||
if name == nil && url == nil && emailAddress == nil {
|
||||
return nil
|
||||
|
@ -31,10 +33,14 @@ public struct Author: Hashable {
|
|||
s += avatarURL ?? ""
|
||||
s += emailAddress ?? ""
|
||||
self.hashValue = s.hashValue
|
||||
|
||||
if databaseID == nil {
|
||||
self.databaseID = (s as NSString).rs_md5Hash()
|
||||
}
|
||||
}
|
||||
|
||||
public static func ==(lhs: Author, rhs: Author) -> Bool {
|
||||
|
||||
return lhs.hashValue == rhs.hashValue && lhs.name == rhs.name && lhs.url == rhs.url && lhs.avatarURL == rhs.avatarURL && lhs.emailAddress == rhs.emailAddress
|
||||
return lhs.hashValue == rhs.hashValue && lhs.databaseID == rhs.databaseID
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
//
|
||||
// AuthorsManager.swift
|
||||
// Database
|
||||
//
|
||||
// Created by Brent Simmons on 7/13/17.
|
||||
// Copyright © 2017 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Data
|
||||
|
||||
final class AuthorsManager {
|
||||
|
||||
var cachedAuthors = [String: Author]()
|
||||
|
||||
func cachedAuthor(_ databaseID: String) -> Author? {
|
||||
|
||||
return cachedAuthors[databaseID]
|
||||
}
|
||||
|
||||
func cacheAuthor(_ author: Author) {
|
||||
|
||||
cachedAuthors[author.databaseID] = author
|
||||
}
|
||||
|
||||
func authorWithRow(_ row: FMResultSet) -> Author? {
|
||||
|
||||
let databaseID = row.string(forColumn: DatabaseKey.databaseID)
|
||||
if let author = cachedAuthor(databaseID) {
|
||||
return author
|
||||
}
|
||||
|
||||
guard let author = Author(row: row) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
cacheAuthor(author)
|
||||
return author
|
||||
}
|
||||
}
|
|
@ -17,7 +17,6 @@
|
|||
8455807C1F0C0DBD003CCFA1 /* Attachment+Database.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8455807B1F0C0DBD003CCFA1 /* Attachment+Database.swift */; };
|
||||
846146271F0ABC7B00870CB3 /* RSParser.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 846146241F0ABC7400870CB3 /* RSParser.framework */; };
|
||||
84BB4BA21F119C5400858766 /* RSCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84BB4B981F119C4900858766 /* RSCore.framework */; };
|
||||
84BB4BA41F119D4A00858766 /* Author+Database.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84BB4BA31F119D4A00858766 /* Author+Database.swift */; };
|
||||
84BB4BA91F11A32800858766 /* TagsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84BB4BA81F11A32800858766 /* TagsManager.swift */; };
|
||||
84E156EA1F0AB80500F8CC05 /* Database.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E156E91F0AB80500F8CC05 /* Database.swift */; };
|
||||
84E156EC1F0AB80E00F8CC05 /* ArticlesManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E156EB1F0AB80E00F8CC05 /* ArticlesManager.swift */; };
|
||||
|
@ -25,6 +24,7 @@
|
|||
84E156F01F0AB81F00F8CC05 /* CreateStatements.sql in Resources */ = {isa = PBXBuildFile; fileRef = 84E156EF1F0AB81F00F8CC05 /* CreateStatements.sql */; };
|
||||
84E156FD1F0AB86100F8CC05 /* Data.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84E156F81F0AB83600F8CC05 /* Data.framework */; };
|
||||
84E1570C1F0AB8A500F8CC05 /* RSDatabase.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84E157071F0AB89B00F8CC05 /* RSDatabase.framework */; };
|
||||
84F20F8F1F180D8700D8E682 /* AuthorsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F20F8E1F180D8700D8E682 /* AuthorsManager.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
|
@ -120,7 +120,6 @@
|
|||
8455807B1F0C0DBD003CCFA1 /* Attachment+Database.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "Attachment+Database.swift"; path = "Extensions/Attachment+Database.swift"; sourceTree = "<group>"; };
|
||||
8461461E1F0ABC7300870CB3 /* RSParser.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RSParser.xcodeproj; path = ../RSParser/RSParser.xcodeproj; sourceTree = "<group>"; };
|
||||
84BB4B8F1F119C4900858766 /* RSCore.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RSCore.xcodeproj; path = ../RSCore/RSCore.xcodeproj; sourceTree = "<group>"; };
|
||||
84BB4BA31F119D4A00858766 /* Author+Database.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "Author+Database.swift"; path = "Extensions/Author+Database.swift"; sourceTree = "<group>"; };
|
||||
84BB4BA81F11A32800858766 /* TagsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagsManager.swift; sourceTree = "<group>"; };
|
||||
84E156E81F0AB75600F8CC05 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
84E156E91F0AB80500F8CC05 /* Database.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Database.swift; sourceTree = "<group>"; };
|
||||
|
@ -129,6 +128,8 @@
|
|||
84E156EF1F0AB81F00F8CC05 /* CreateStatements.sql */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CreateStatements.sql; sourceTree = "<group>"; };
|
||||
84E156F11F0AB83600F8CC05 /* Data.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Data.xcodeproj; path = ../Data/Data.xcodeproj; sourceTree = "<group>"; };
|
||||
84E157001F0AB89B00F8CC05 /* RSDatabase.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RSDatabase.xcodeproj; path = ../RSDatabase/RSDatabase.xcodeproj; sourceTree = "<group>"; };
|
||||
84F20F8E1F180D8700D8E682 /* AuthorsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthorsManager.swift; sourceTree = "<group>"; };
|
||||
84F20F901F1810DD00D8E682 /* Author+Database.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "Author+Database.swift"; path = "Extensions/Author+Database.swift"; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
|
@ -161,6 +162,7 @@
|
|||
845580661F0AEBCD003CCFA1 /* Constants.swift */,
|
||||
84E156EB1F0AB80E00F8CC05 /* ArticlesManager.swift */,
|
||||
84E156ED1F0AB81400F8CC05 /* StatusesManager.swift */,
|
||||
84F20F8E1F180D8700D8E682 /* AuthorsManager.swift */,
|
||||
84BB4BA81F11A32800858766 /* TagsManager.swift */,
|
||||
8461462A1F0AC44100870CB3 /* Extensions */,
|
||||
84E156EF1F0AB81F00F8CC05 /* CreateStatements.sql */,
|
||||
|
@ -204,8 +206,8 @@
|
|||
845580771F0AF678003CCFA1 /* Folder+Database.swift */,
|
||||
845580751F0AF670003CCFA1 /* Article+Database.swift */,
|
||||
845580791F0AF67D003CCFA1 /* ArticleStatus+Database.swift */,
|
||||
84F20F901F1810DD00D8E682 /* Author+Database.swift */,
|
||||
8455807B1F0C0DBD003CCFA1 /* Attachment+Database.swift */,
|
||||
84BB4BA31F119D4A00858766 /* Author+Database.swift */,
|
||||
845580711F0AEE49003CCFA1 /* AccountInfo.swift */,
|
||||
);
|
||||
name = Extensions;
|
||||
|
@ -459,12 +461,12 @@
|
|||
84E156EC1F0AB80E00F8CC05 /* ArticlesManager.swift in Sources */,
|
||||
84E156EE1F0AB81400F8CC05 /* StatusesManager.swift in Sources */,
|
||||
8455807C1F0C0DBD003CCFA1 /* Attachment+Database.swift in Sources */,
|
||||
84F20F8F1F180D8700D8E682 /* AuthorsManager.swift in Sources */,
|
||||
845580671F0AEBCD003CCFA1 /* Constants.swift in Sources */,
|
||||
845580781F0AF678003CCFA1 /* Folder+Database.swift in Sources */,
|
||||
845580761F0AF670003CCFA1 /* Article+Database.swift in Sources */,
|
||||
845580721F0AEE49003CCFA1 /* AccountInfo.swift in Sources */,
|
||||
8455807A1F0AF67D003CCFA1 /* ArticleStatus+Database.swift in Sources */,
|
||||
84BB4BA41F119D4A00858766 /* Author+Database.swift in Sources */,
|
||||
84BB4BA91F11A32800858766 /* TagsManager.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
|
|
@ -14,11 +14,12 @@ extension Author {
|
|||
|
||||
init?(row: FMResultSet) {
|
||||
|
||||
let databaseID = row.string(forColumn: DatabaseKey.databaseID)
|
||||
let name = row.string(forColumn: DatabaseKey.name)
|
||||
let url = row.string(forColumn: DatabaseKey.url)
|
||||
let avatarURL = row.string(forColumn: DatabaseKey.avatarURL)
|
||||
let emailAddress = row.string(forColumn: DatabaseKey.emailAddress)
|
||||
|
||||
self.init(name: name, url: url, avatarURL: avatarURL, emailAddress: emailAddress)
|
||||
self.init(databaseID: databaseID, name: name, url: url, avatarURL: avatarURL, emailAddress: emailAddress)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue