Rename Manager to Table. Conform to DatabaseTable protocol.

This commit is contained in:
Brent Simmons 2017-07-29 12:08:10 -07:00
parent 961454a447
commit 02174012ec
7 changed files with 56 additions and 35 deletions

View File

@ -1,5 +1,5 @@
//
// ArticlesManager.swift
// ArticlesTable.swift
// Evergreen
//
// Created by Brent Simmons on 5/9/16.
@ -9,7 +9,14 @@
import Foundation
import Data
final class ArticlesManager {
final class ArticlesTable: DatabaseTable {
let name: String
init(name: String) {
self.name = name
}
private let cachedArticles: NSMapTable<NSString, Article> = NSMapTable.weakToWeakObjects()

View File

@ -31,6 +31,12 @@ import Data
final class AttachmentsTable: DatabaseTable {
let name: String
init(name: String) {
self.name = name
}
private var cachedAttachments = [String: Attachment]() // Attachment.databaseID key
private var cachedAttachmentsByArticle = [String: Set<Attachment>]() // Article.databaseID key
private var articlesWithNoAttachments = Set<String>() // Article.databaseID

View File

@ -1,5 +1,5 @@
//
// AuthorsManager.swift
// AuthorsTable.swift
// Database
//
// Created by Brent Simmons on 7/13/17.
@ -9,8 +9,15 @@
import Foundation
import Data
final class AuthorsManager {
final class AuthorsTable: DatabaseTable {
let name: String
init(name: String) {
self.name = name
}
var cachedAuthors = [String: Author]()
func cachedAuthor(_ databaseID: String) -> Author? {

View File

@ -26,6 +26,7 @@ final class Database {
fileprivate let queue: RSDatabaseQueue
private let databaseFile: String
private let attachmentsTable = AttachmentsTable(DatabaseTableName.attachments)
fileprivate let statusesManager: StatusesManager
fileprivate let articleCache = ArticlesManager()
fileprivate var articleArrivalCutoffDate = NSDate.rs_dateWithNumberOfDays(inThePast: 3 * 31)!

View File

@ -7,7 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
840405CF1F1A963700DF0296 /* AttachmentsTable..swift in Sources */ = {isa = PBXBuildFile; fileRef = 840405CE1F1A963700DF0296 /* AttachmentsTable..swift */; };
840405CF1F1A963700DF0296 /* AttachmentsTable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 840405CE1F1A963700DF0296 /* AttachmentsTable.swift */; };
844BEE411F0AB3AB004AB7CD /* Database.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 844BEE371F0AB3AA004AB7CD /* Database.framework */; };
844BEE461F0AB3AB004AB7CD /* DatabaseTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 844BEE451F0AB3AB004AB7CD /* DatabaseTests.swift */; };
845580671F0AEBCD003CCFA1 /* Constants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 845580661F0AEBCD003CCFA1 /* Constants.swift */; };
@ -18,14 +18,14 @@
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 */; };
84BB4BA91F11A32800858766 /* TagsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84BB4BA81F11A32800858766 /* TagsManager.swift */; };
84BB4BA91F11A32800858766 /* TagsTable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84BB4BA81F11A32800858766 /* TagsTable.swift */; };
84E156EA1F0AB80500F8CC05 /* Database.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E156E91F0AB80500F8CC05 /* Database.swift */; };
84E156EC1F0AB80E00F8CC05 /* ArticlesManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E156EB1F0AB80E00F8CC05 /* ArticlesManager.swift */; };
84E156EE1F0AB81400F8CC05 /* StatusesManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E156ED1F0AB81400F8CC05 /* StatusesManager.swift */; };
84E156EC1F0AB80E00F8CC05 /* ArticlesTable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E156EB1F0AB80E00F8CC05 /* ArticlesTable.swift */; };
84E156EE1F0AB81400F8CC05 /* StatusesTable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84E156ED1F0AB81400F8CC05 /* StatusesTable.swift */; };
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 */; };
84F20F8F1F180D8700D8E682 /* AuthorsTable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84F20F8E1F180D8700D8E682 /* AuthorsTable.swift */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@ -109,7 +109,7 @@
/* End PBXContainerItemProxy section */
/* Begin PBXFileReference section */
840405CE1F1A963700DF0296 /* AttachmentsTable..swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttachmentsTable..swift; sourceTree = "<group>"; };
840405CE1F1A963700DF0296 /* AttachmentsTable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttachmentsTable.swift; sourceTree = "<group>"; };
844BEE371F0AB3AA004AB7CD /* Database.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Database.framework; sourceTree = BUILT_PRODUCTS_DIR; };
844BEE401F0AB3AB004AB7CD /* DatabaseTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DatabaseTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
844BEE451F0AB3AB004AB7CD /* DatabaseTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatabaseTests.swift; sourceTree = "<group>"; };
@ -122,15 +122,15 @@
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>"; };
84BB4BA81F11A32800858766 /* TagsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagsManager.swift; sourceTree = "<group>"; };
84BB4BA81F11A32800858766 /* TagsTable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagsTable.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>"; };
84E156EB1F0AB80E00F8CC05 /* ArticlesManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArticlesManager.swift; sourceTree = "<group>"; };
84E156ED1F0AB81400F8CC05 /* StatusesManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusesManager.swift; sourceTree = "<group>"; };
84E156EB1F0AB80E00F8CC05 /* ArticlesTable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ArticlesTable.swift; sourceTree = "<group>"; };
84E156ED1F0AB81400F8CC05 /* StatusesTable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatusesTable.swift; sourceTree = "<group>"; };
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>"; };
84F20F8E1F180D8700D8E682 /* AuthorsTable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthorsTable.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 */
@ -162,11 +162,11 @@
children = (
84E156E91F0AB80500F8CC05 /* Database.swift */,
845580661F0AEBCD003CCFA1 /* Constants.swift */,
84E156EB1F0AB80E00F8CC05 /* ArticlesManager.swift */,
84E156ED1F0AB81400F8CC05 /* StatusesManager.swift */,
84F20F8E1F180D8700D8E682 /* AuthorsManager.swift */,
840405CE1F1A963700DF0296 /* AttachmentsTable..swift */,
84BB4BA81F11A32800858766 /* TagsManager.swift */,
84E156EB1F0AB80E00F8CC05 /* ArticlesTable.swift */,
84E156ED1F0AB81400F8CC05 /* StatusesTable.swift */,
84F20F8E1F180D8700D8E682 /* AuthorsTable.swift */,
840405CE1F1A963700DF0296 /* AttachmentsTable.swift */,
84BB4BA81F11A32800858766 /* TagsTable.swift */,
8461462A1F0AC44100870CB3 /* Extensions */,
84E156EF1F0AB81F00F8CC05 /* CreateStatements.sql */,
84E156E81F0AB75600F8CC05 /* Info.plist */,
@ -461,17 +461,17 @@
buildActionMask = 2147483647;
files = (
84E156EA1F0AB80500F8CC05 /* Database.swift in Sources */,
84E156EC1F0AB80E00F8CC05 /* ArticlesManager.swift in Sources */,
84E156EE1F0AB81400F8CC05 /* StatusesManager.swift in Sources */,
84E156EC1F0AB80E00F8CC05 /* ArticlesTable.swift in Sources */,
84E156EE1F0AB81400F8CC05 /* StatusesTable.swift in Sources */,
8455807C1F0C0DBD003CCFA1 /* Attachment+Database.swift in Sources */,
84F20F8F1F180D8700D8E682 /* AuthorsManager.swift in Sources */,
84F20F8F1F180D8700D8E682 /* AuthorsTable.swift in Sources */,
845580671F0AEBCD003CCFA1 /* Constants.swift in Sources */,
840405CF1F1A963700DF0296 /* AttachmentsTable..swift in Sources */,
840405CF1F1A963700DF0296 /* AttachmentsTable.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 */,
84BB4BA91F11A32800858766 /* TagsManager.swift in Sources */,
84BB4BA91F11A32800858766 /* TagsTable.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -1,5 +1,5 @@
//
// StatusesManager.swift
// StatusesTable.swift
// Evergreen
//
// Created by Brent Simmons on 5/8/16.
@ -12,14 +12,14 @@ import RSDatabase
import RSParser
import Data
final class StatusesManager {
final class StatusesTable: DatabaseTable {
var cachedStatuses = [String: ArticleStatus]()
let queue: RSDatabaseQueue
let name: String
init(queue: RSDatabaseQueue) {
init(name: String) {
self.queue = queue
self.name = name
}
func markArticles(_ articles: Set<Article>, statusKey: String, flag: Bool) {

View File

@ -16,16 +16,16 @@ import Data
typealias TagNameSet = Set<String>
final class TagsManager {
final class TagsTable: DatabaseTable {
let name: String
private var articleIDCache = [String: TagNameSet]() // articleID: tags
private var articleIDsWithNoTags = TagNameSet()
private let queue: RSDatabaseQueue
init(name: String) {
init(queue: RSDatabaseQueue) {
self.queue = queue
self.name = name
}
func saveTagsForArticles(_ articles: Set<Article>) {