From 90c11bb687db1b03f67303bfeb7a4e2a9d13ed79 Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sat, 16 Sep 2017 10:38:54 -0700 Subject: [PATCH] Delete some unused code. --- Frameworks/Database/Constants.swift | 16 -- Frameworks/Database/Database.swift | 172 +----------------- .../Database.xcodeproj/project.pbxproj | 2 +- 3 files changed, 8 insertions(+), 182 deletions(-) diff --git a/Frameworks/Database/Constants.swift b/Frameworks/Database/Constants.swift index b3f81cd94..d12ea3b70 100644 --- a/Frameworks/Database/Constants.swift +++ b/Frameworks/Database/Constants.swift @@ -8,21 +8,6 @@ import Foundation -// MARK: - Notifications - -public extension Notification.Name { - - public static let ArticlesDidSave = Notification.Name(rawValue: "ArticlesDidSave") -} - -public struct DatabaseNotificationKey { - - // userInfo keys (with Set
values) for ArticlesDidSave. - // One or both will be present. If present, may be empty. - static let newArticles = "newArticles" - static let updatedArticles = "updatedArticles" -} - // MARK: - Database structure struct DatabaseTableName { @@ -39,7 +24,6 @@ struct DatabaseTableName { struct DatabaseKey { // Shared - static let databaseID = "databaseID" static let articleID = "articleID" static let accountInfo = "accountInfo" static let url = "url" diff --git a/Frameworks/Database/Database.swift b/Frameworks/Database/Database.swift index 4c7f41fe6..508b21009 100644 --- a/Frameworks/Database/Database.swift +++ b/Frameworks/Database/Database.swift @@ -12,25 +12,23 @@ import RSDatabase import RSParser import Data +// This file and UnreadCountDictionary are the entirety of the public API for Database.framework. +// Everything else is implementation. + public typealias ArticleResultBlock = (Set
) -> Void public typealias UnreadCountCompletionBlock = (UnreadCountDictionary) -> Void -public typealias UpdateArticlesWithFeedCompletionBlock = (Set
?, Set
?) -> Void //newArticles, updateArticles +public typealias UpdateArticlesWithFeedCompletionBlock = (Set
?, Set
?) -> Void //newArticles, updatedArticles public final class Database { private let accountID: String - private let queue: RSDatabaseQueue - private let databaseFile: String private let articlesTable: ArticlesTable - private var articleArrivalCutoffDate = NSDate.rs_dateWithNumberOfDays(inThePast: 3 * 31)! - private let minimumNumberOfArticles = 10 public init(databaseFile: String, accountID: String) { self.accountID = accountID - self.databaseFile = databaseFile - self.queue = RSDatabaseQueue(filepath: databaseFile, excludeFromBackup: false) - + + let queue = RSDatabaseQueue(filepath: databaseFile, excludeFromBackup: false) self.articlesTable = ArticlesTable(name: DatabaseTableName.articles, accountID: accountID, queue: queue) let createStatementsPath = Bundle(for: type(of: self)).path(forResource: "CreateStatements", ofType: "sql")! @@ -63,7 +61,7 @@ public final class Database { articlesTable.fetchUnreadCounts(feeds, completion) } - // MARK: - Updating Articles + // MARK: - Saving and Updating Articles public func update(feed: Feed, parsedFeed: ParsedFeed, completion: @escaping UpdateArticlesWithFeedCompletionBlock) { @@ -78,159 +76,3 @@ public final class Database { } } -// MARK: - Private - -private extension Database { - - - - - // MARK: Saving Articles - -// func saveUpdatedAndNewArticles(_ articleChanges: Set, newArticles: Set
) { -// -// if articleChanges.isEmpty && newArticles.isEmpty { -// return -// } -// -// statusesTable.assertNoMissingStatuses(newArticles) -// articleCache.cacheArticles(newArticles) -// -// let newArticleDictionaries = newArticles.map { (oneArticle) in -// return oneArticle.databaseDictionary() -// } -// -// queue.update { (database: FMDatabase!) -> Void in -// -// if !articleChanges.isEmpty { -// -// for oneDictionary in articleChanges { -// -// let oneArticleDictionary = oneDictionary.mutableCopy() as! NSMutableDictionary -// let articleID = oneArticleDictionary[DatabaseKey.articleID]! -// oneArticleDictionary.removeObject(forKey: DatabaseKey.articleID) -// -// let _ = database.rs_updateRows(with: oneArticleDictionary as [NSObject: AnyObject], whereKey: DatabaseKey.articleID, equalsValue: articleID, tableName: DatabaseTableName.articles) -// } -// -// } -// if !newArticleDictionaries.isEmpty { -// -// for oneNewArticleDictionary in newArticleDictionaries { -// let _ = database.rs_insertRow(with: oneNewArticleDictionary as [NSObject: AnyObject], insertType: RSDatabaseInsertOrReplace, tableName: DatabaseTableName.articles) -// } -// } -// } -// } -// -// // MARK: Updating Articles -// -// func updateArticles(_ articles: [String: Article], parsedArticles: [String: ParsedItem], feed: Feed, completionHandler: @escaping RSVoidCompletionBlock) { -// -// statusesTable.ensureStatusesForParsedArticles(Set(parsedArticles.values)) { -// -// let articleChanges = self.updateExistingArticles(articles, parsedArticles) -// let newArticles = self.createNewArticles(articles, parsedArticles: parsedArticles, feedID: feed.feedID) -// -// self.saveUpdatedAndNewArticles(articleChanges, newArticles: newArticles) -// -// completionHandler() -// } -// } -// -// func articlesDictionary(_ articles: NSSet) -> [String: AnyObject] { -// -// var d = [String: AnyObject]() -// for oneArticle in articles { -// let oneArticleID = (oneArticle as AnyObject).value(forKey: DatabaseKey.articleID) as! String -// d[oneArticleID] = oneArticle as AnyObject -// } -// return d -// } -// -// func updateExistingArticles(_ articles: [String: Article], _ parsedArticles: [String: ParsedItem]) -> Set { -// -// var articleChanges = Set() -// -// for oneArticle in articles.values { -// if let oneParsedArticle = parsedArticles[oneArticle.articleID] { -// if let oneArticleChanges = oneArticle.updateWithParsedArticle(oneParsedArticle) { -// articleChanges.insert(oneArticleChanges) -// } -// } -// } -// -// return articleChanges -// } -// -// // MARK: Creating Articles -// -// func createNewArticlesWithParsedArticles(_ parsedArticles: Set, feedID: String) -> Set
{ -// -// return Set(parsedArticles.map { Article(account: account, feedID: feedID, parsedArticle: $0) }) -// } -// -// func articlesWithParsedArticles(_ parsedArticles: Set, feedID: String) -> Set
{ -// -// var localArticles = Set
() -// -// for oneParsedArticle in parsedArticles { -// let oneLocalArticle = Article(account: self.account, feedID: feedID, parsedArticle: oneParsedArticle) -// localArticles.insert(oneLocalArticle) -// } -// -// return localArticles -// } -// -// func createNewArticles(_ existingArticles: [String: Article], parsedArticles: [String: ParsedItem], feedID: String) -> Set
{ -// -// let newParsedArticles = parsedArticlesMinusExistingArticles(parsedArticles, existingArticles: existingArticles) -// let newArticles = createNewArticlesWithParsedArticles(newParsedArticles, feedID: feedID) -// -// statusesTable.attachCachedUniqueStatuses(newArticles) -// -// return newArticles -// } -// -// func parsedArticlesMinusExistingArticles(_ parsedArticles: [String: ParsedItem], existingArticles: [String: Article]) -> Set { -// -// var result = Set() -// -// for oneParsedArticle in parsedArticles.values { -// -// if let _ = existingArticles[oneParsedArticle.databaseID] { -// continue -// } -// result.insert(oneParsedArticle) -// } -// -// return result -// } -// -// // MARK: Filtering out old articles -// -// func articleIsOlderThanCutoffDate(_ article: Article) -> Bool { -// -// if let dateArrived = article.status?.dateArrived { -// return dateArrived < articleArrivalCutoffDate -// } -// return false -// } -// -// func articleShouldAppearToUser(_ article: Article, _ numberOfArticlesInFeed: Int) -> Bool { -// -// if numberOfArticlesInFeed <= minimumNumberOfArticles { -// return true -// } -// return articleShouldBeSavedForever(article) || !articleIsOlderThanCutoffDate(article) -// } -// -// -// func deletePossibleOldArticles(_ articles: Set
) { -// -// let feedIDs = feedIDsFromArticles(articles) -// if feedIDs.isEmpty { -// return -// } -// } -} diff --git a/Frameworks/Database/Database.xcodeproj/project.pbxproj b/Frameworks/Database/Database.xcodeproj/project.pbxproj index d9e4bf76d..6ac33d881 100644 --- a/Frameworks/Database/Database.xcodeproj/project.pbxproj +++ b/Frameworks/Database/Database.xcodeproj/project.pbxproj @@ -168,13 +168,13 @@ isa = PBXGroup; children = ( 84E156E91F0AB80500F8CC05 /* Database.swift */, + 848AD2951F58A91E004FB0EC /* UnreadCountDictionary.swift */, 845580661F0AEBCD003CCFA1 /* Constants.swift */, 84E156EB1F0AB80E00F8CC05 /* ArticlesTable.swift */, 84E156ED1F0AB81400F8CC05 /* StatusesTable.swift */, 84F20F8E1F180D8700D8E682 /* AuthorsTable.swift */, 84BB4BA81F11A32800858766 /* TagsTable.swift */, 840405CE1F1A963700DF0296 /* AttachmentsTable.swift */, - 848AD2951F58A91E004FB0EC /* UnreadCountDictionary.swift */, 8461462A1F0AC44100870CB3 /* Extensions */, 84E156EF1F0AB81F00F8CC05 /* CreateStatements.sql */, 84E156E81F0AB75600F8CC05 /* Info.plist */,