Begin moving database stuff from LocalAccount.framework to Data.framework.

This commit is contained in:
Brent Simmons 2017-07-08 13:32:09 -07:00
parent 7ce6390f23
commit d0a4effe07
4 changed files with 62 additions and 98 deletions

View File

@ -84,6 +84,7 @@
844BEE961F0AB4F8004AB7CD /* DisplayNameProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DisplayNameProvider.swift; sourceTree = "<group>"; }; 844BEE961F0AB4F8004AB7CD /* DisplayNameProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DisplayNameProvider.swift; sourceTree = "<group>"; };
844BEE971F0AB4F8004AB7CD /* UnreadCountProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UnreadCountProvider.swift; sourceTree = "<group>"; }; 844BEE971F0AB4F8004AB7CD /* UnreadCountProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UnreadCountProvider.swift; sourceTree = "<group>"; };
844BEE9C1F0AB512004AB7CD /* RSCore.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RSCore.xcodeproj; path = ../RSCore/RSCore.xcodeproj; sourceTree = "<group>"; }; 844BEE9C1F0AB512004AB7CD /* RSCore.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RSCore.xcodeproj; path = ../RSCore/RSCore.xcodeproj; sourceTree = "<group>"; };
84BB4B7C1F1177AD00858766 /* ArticleCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArticleCache.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@ -118,6 +119,7 @@
844BEE841F0AB4DB004AB7CD /* ArticleStatus.swift */, 844BEE841F0AB4DB004AB7CD /* ArticleStatus.swift */,
844BEE861F0AB4E3004AB7CD /* BatchUpdates.swift */, 844BEE861F0AB4E3004AB7CD /* BatchUpdates.swift */,
844BEE881F0AB4E7004AB7CD /* Notifications.swift */, 844BEE881F0AB4E7004AB7CD /* Notifications.swift */,
84BB4B7B1F1177AD00858766 /* Database */,
844BEE8A1F0AB4EF004AB7CD /* OPML */, 844BEE8A1F0AB4EF004AB7CD /* OPML */,
844BEE931F0AB4F8004AB7CD /* Protocols */, 844BEE931F0AB4F8004AB7CD /* Protocols */,
844BEE761F0AB444004AB7CD /* Info.plist */, 844BEE761F0AB444004AB7CD /* Info.plist */,
@ -185,6 +187,14 @@
name = Frameworks; name = Frameworks;
sourceTree = "<group>"; sourceTree = "<group>";
}; };
84BB4B7B1F1177AD00858766 /* Database */ = {
isa = PBXGroup;
children = (
84BB4B7C1F1177AD00858766 /* ArticleCache.swift */,
);
path = Database;
sourceTree = "<group>";
};
/* End PBXGroup section */ /* End PBXGroup section */
/* Begin PBXHeadersBuildPhase section */ /* Begin PBXHeadersBuildPhase section */

View File

@ -0,0 +1,52 @@
//
// ArticleCache.swift
// Evergreen
//
// Created by Brent Simmons on 5/9/16.
// Copyright © 2016 Ranchero Software, LLC. All rights reserved.
//
import Foundation
final class ArticleCache {
private var cachedArticles: NSMapTable<NSString, LocalArticle> = NSMapTable.weakToWeakObjects()
private let statusesManager: StatusesManager
func uniquedArticles(_ fetchedArticles: Set<Article>, statusesManager: StatusesManager) -> Set<Article> {
var articles = Set<Article>()
for oneArticle in fetchedArticles {
assert(oneArticle.status != nil)
if let existingArticle = cachedArticle(oneArticle.articleID) {
articles.insert(existingArticle)
}
else {
cacheArticle(oneArticle)
articles.insert(oneArticle)
}
}
statusesManager.attachCachedUniqueStatuses(articles)
return articles
}
func cachedArticle(_ articleID: String) -> Article? {
return cachedArticles.object(forKey: articleID as NSString)
}
func cacheArticle(_ article: Article) {
cachedArticles.setObject(article, forKey: article.articleID as NSString)
}
func cacheArticles(_ articles: Set<Article>) {
articles.forEach { cacheArticle($0) }
}
}

View File

@ -14,7 +14,6 @@
8471A2E51ED4D007008F099E /* LocalArticle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8471A2E41ED4D007008F099E /* LocalArticle.swift */; }; 8471A2E51ED4D007008F099E /* LocalArticle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8471A2E41ED4D007008F099E /* LocalArticle.swift */; };
8471A2E71ED4D012008F099E /* LocalArticleStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8471A2E61ED4D012008F099E /* LocalArticleStatus.swift */; }; 8471A2E71ED4D012008F099E /* LocalArticleStatus.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8471A2E61ED4D012008F099E /* LocalArticleStatus.swift */; };
8471A2E91ED4D01B008F099E /* DiskDictionaryConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8471A2E81ED4D01B008F099E /* DiskDictionaryConstants.swift */; }; 8471A2E91ED4D01B008F099E /* DiskDictionaryConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8471A2E81ED4D01B008F099E /* DiskDictionaryConstants.swift */; };
8471A2FA1ED4D098008F099E /* LocalArticleCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8471A2F91ED4D098008F099E /* LocalArticleCache.swift */; };
8471A2FC1ED4D0A1008F099E /* LocalDatabase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8471A2FB1ED4D0A1008F099E /* LocalDatabase.swift */; }; 8471A2FC1ED4D0A1008F099E /* LocalDatabase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8471A2FB1ED4D0A1008F099E /* LocalDatabase.swift */; };
8471A2FE1ED4D0AD008F099E /* LocalStatusesManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8471A2FD1ED4D0AD008F099E /* LocalStatusesManager.swift */; }; 8471A2FE1ED4D0AD008F099E /* LocalStatusesManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8471A2FD1ED4D0AD008F099E /* LocalStatusesManager.swift */; };
8471A3001ED4D0B8008F099E /* LocalCreateStatements.sql in Resources */ = {isa = PBXBuildFile; fileRef = 8471A2FF1ED4D0B8008F099E /* LocalCreateStatements.sql */; }; 8471A3001ED4D0B8008F099E /* LocalCreateStatements.sql in Resources */ = {isa = PBXBuildFile; fileRef = 8471A2FF1ED4D0B8008F099E /* LocalCreateStatements.sql */; };
@ -47,7 +46,6 @@
8471A2E61ED4D012008F099E /* LocalArticleStatus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocalArticleStatus.swift; sourceTree = "<group>"; }; 8471A2E61ED4D012008F099E /* LocalArticleStatus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocalArticleStatus.swift; sourceTree = "<group>"; };
8471A2E81ED4D01B008F099E /* DiskDictionaryConstants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DiskDictionaryConstants.swift; sourceTree = "<group>"; }; 8471A2E81ED4D01B008F099E /* DiskDictionaryConstants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DiskDictionaryConstants.swift; sourceTree = "<group>"; };
8471A2EA1ED4D02F008F099E /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 8471A2EA1ED4D02F008F099E /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
8471A2F91ED4D098008F099E /* LocalArticleCache.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocalArticleCache.swift; sourceTree = "<group>"; };
8471A2FB1ED4D0A1008F099E /* LocalDatabase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocalDatabase.swift; sourceTree = "<group>"; }; 8471A2FB1ED4D0A1008F099E /* LocalDatabase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocalDatabase.swift; sourceTree = "<group>"; };
8471A2FD1ED4D0AD008F099E /* LocalStatusesManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocalStatusesManager.swift; sourceTree = "<group>"; }; 8471A2FD1ED4D0AD008F099E /* LocalStatusesManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocalStatusesManager.swift; sourceTree = "<group>"; };
8471A2FF1ED4D0B8008F099E /* LocalCreateStatements.sql */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LocalCreateStatements.sql; sourceTree = "<group>"; }; 8471A2FF1ED4D0B8008F099E /* LocalCreateStatements.sql */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LocalCreateStatements.sql; sourceTree = "<group>"; };
@ -91,7 +89,6 @@
8442EB3F1D68C8B200D709AE /* Database */ = { 8442EB3F1D68C8B200D709AE /* Database */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
8471A2F91ED4D098008F099E /* LocalArticleCache.swift */,
8471A2FB1ED4D0A1008F099E /* LocalDatabase.swift */, 8471A2FB1ED4D0A1008F099E /* LocalDatabase.swift */,
8471A2FD1ED4D0AD008F099E /* LocalStatusesManager.swift */, 8471A2FD1ED4D0AD008F099E /* LocalStatusesManager.swift */,
8471A2FF1ED4D0B8008F099E /* LocalCreateStatements.sql */, 8471A2FF1ED4D0B8008F099E /* LocalCreateStatements.sql */,
@ -263,7 +260,6 @@
8471A2E91ED4D01B008F099E /* DiskDictionaryConstants.swift in Sources */, 8471A2E91ED4D01B008F099E /* DiskDictionaryConstants.swift in Sources */,
8471A2E11ED4CFF3008F099E /* LocalFolder.swift in Sources */, 8471A2E11ED4CFF3008F099E /* LocalFolder.swift in Sources */,
8471A2E51ED4D007008F099E /* LocalArticle.swift in Sources */, 8471A2E51ED4D007008F099E /* LocalArticle.swift in Sources */,
8471A2FA1ED4D098008F099E /* LocalArticleCache.swift in Sources */,
8471A2E71ED4D012008F099E /* LocalArticleStatus.swift in Sources */, 8471A2E71ED4D012008F099E /* LocalArticleStatus.swift in Sources */,
8471A2FC1ED4D0A1008F099E /* LocalDatabase.swift in Sources */, 8471A2FC1ED4D0A1008F099E /* LocalDatabase.swift in Sources */,
8471A2E31ED4CFFB008F099E /* LocalFeed.swift in Sources */, 8471A2E31ED4CFFB008F099E /* LocalFeed.swift in Sources */,

View File

@ -1,94 +0,0 @@
//
// LocalArticleCache.swift
// Evergreen
//
// Created by Brent Simmons on 5/9/16.
// Copyright © 2016 Ranchero Software, LLC. All rights reserved.
//
import Foundation
final class LocalArticleCache {
private var cachedArticles: NSMapTable<NSString, LocalArticle> = NSMapTable.weakToWeakObjects()
// private var cachedArticles = [String: LocalArticle]()
// fileprivate var articlesByFeedID = [String: Set<LocalArticle>]()
private let statusesManager: LocalStatusesManager
init(statusesManager: LocalStatusesManager) {
self.statusesManager = statusesManager
}
func uniquedArticles(_ fetchedArticles: Set<LocalArticle>) -> Set<LocalArticle> {
var articles = Set<LocalArticle>()
for oneArticle in fetchedArticles {
assert(oneArticle.status != nil)
if let existingArticle = cachedArticle(oneArticle.articleID) {
articles.insert(existingArticle)
}
else {
cacheArticle(oneArticle)
articles.insert(oneArticle)
}
}
statusesManager.attachCachedUniqueStatuses(articles)
return articles
}
func cachedArticle(_ articleID: String) -> LocalArticle? {
return cachedArticles.object(forKey: articleID as NSString)
// return cachedArticles[articleID]
}
func cacheArticle(_ article: LocalArticle) {
cachedArticles.setObject(article, forKey: article.articleID as NSString)
// cachedArticles[article.articleID] = article
// addToCachedArticlesForFeedID(Set([article]))
}
func cacheArticles(_ articles: Set<LocalArticle>) {
articles.forEach { cacheArticle($0) }
// addToCachedArticlesForFeedID(articles)
}
// func cachedArticlesForFeedID(_ feedID: String) -> Set<LocalArticle>? {
//
// return articlesByFeedID[feedID]
// }
}
//private extension LocalArticleCache {
//
// func addToCachedArticlesForFeedID(_ feedID: String, _ articles: Set<LocalArticle>) {
//
// if let cachedArticles = cachedArticlesForFeedID(feedID) {
// replaceCachedArticlesForFeedID(feedID, cachedArticles.union(articles))
// }
// else {
// replaceCachedArticlesForFeedID(feedID, articles)
// }
// }
//
// func addToCachedArticlesForFeedID(_ articles: Set<LocalArticle>) {
//
// for oneArticle in articles {
// addToCachedArticlesForFeedID(oneArticle.feedID, Set([oneArticle]))
// }
// }
//
// func replaceCachedArticlesForFeedID(_ feedID: String, _ articles: Set<LocalArticle>) {
//
// articlesByFeedID[feedID] = articles
// }
//
//}