diff --git a/Account/Sources/Account/Account.swift b/Account/Sources/Account/Account.swift index 98072ea84..824c2526d 100644 --- a/Account/Sources/Account/Account.swift +++ b/Account/Sources/Account/Account.swift @@ -331,7 +331,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, self.metadata.performedApril2020RetentionPolicyChange = true } - self.database.cleanupDatabaseAtStartup(subscribedToWebFeedIDs: self.flattenedWebFeeds().webFeedIDs()) + self.database.cleanupDatabaseAtStartup(subscribedToFeedIDs: self.flattenedWebFeeds().webFeedIDs()) self.fetchAllUnreadCounts() } @@ -780,7 +780,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, precondition(Thread.isMainThread) precondition(type == .onMyMac || type == .cloudKit) - database.update(with: parsedItems, webFeedID: webFeedID, deleteOlder: deleteOlder) { updateArticlesResult in + database.update(with: parsedItems, feedID: webFeedID, deleteOlder: deleteOlder) { updateArticlesResult in switch updateArticlesResult { case .success(let articleChanges): self.sendNotificationAbout(articleChanges) @@ -800,7 +800,7 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container, return } - database.update(webFeedIDsAndItems: webFeedIDsAndItems, defaultRead: defaultRead) { updateArticlesResult in + database.update(feedIDsAndItems: webFeedIDsAndItems, defaultRead: defaultRead) { updateArticlesResult in switch updateArticlesResult { case .success(let newAndUpdatedArticles): self.sendNotificationAbout(newAndUpdatedArticles) diff --git a/Articles/Sources/Articles/Article.swift b/Articles/Sources/Articles/Article.swift index a979c7229..0f2796716 100644 --- a/Articles/Sources/Articles/Article.swift +++ b/Articles/Sources/Articles/Article.swift @@ -48,12 +48,12 @@ public struct Article: Hashable { self.articleID = articleID } else { - self.articleID = Article.calculatedArticleID(webFeedID: webFeedID, uniqueID: uniqueID) + self.articleID = Article.calculatedArticleID(feedID: webFeedID, uniqueID: uniqueID) } } - public static func calculatedArticleID(webFeedID: String, uniqueID: String) -> String { - return databaseIDWithString("\(webFeedID) \(uniqueID)") + public static func calculatedArticleID(feedID: String, uniqueID: String) -> String { + return databaseIDWithString("\(feedID) \(uniqueID)") } // MARK: - Hashable diff --git a/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabase.swift b/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabase.swift index 3ba2fcedc..84731459b 100644 --- a/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabase.swift +++ b/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesDatabase.swift @@ -17,7 +17,7 @@ import Articles // Main thread only. -public typealias UnreadCountDictionary = [String: Int] // webFeedID: unreadCount +public typealias UnreadCountDictionary = [String: Int] // feedID: unreadCount public typealias UnreadCountDictionaryCompletionResult = Result public typealias UnreadCountDictionaryCompletionBlock = (UnreadCountDictionaryCompletionResult) -> Void @@ -90,44 +90,44 @@ public final class ArticlesDatabase { // MARK: - Fetching Articles - public func fetchArticles(_ webFeedID: String) throws -> Set
{ - return try articlesTable.fetchArticles(webFeedID) + public func fetchArticles(_ feedID: String) throws -> Set
{ + return try articlesTable.fetchArticles(feedID) } - public func fetchArticles(_ webFeedIDs: Set) throws -> Set
{ - return try articlesTable.fetchArticles(webFeedIDs) + public func fetchArticles(_ feedIDs: Set) throws -> Set
{ + return try articlesTable.fetchArticles(feedIDs) } public func fetchArticles(articleIDs: Set) throws -> Set
{ return try articlesTable.fetchArticles(articleIDs: articleIDs) } - public func fetchUnreadArticles(_ webFeedIDs: Set, _ limit: Int?) throws -> Set
{ - return try articlesTable.fetchUnreadArticles(webFeedIDs, limit) + public func fetchUnreadArticles(_ feedIDs: Set, _ limit: Int?) throws -> Set
{ + return try articlesTable.fetchUnreadArticles(feedIDs, limit) } public func fetchArticlesBetween(articleIDs: Set, before: Date?, after: Date?) throws -> Set
{ return try articlesTable.fetchArticlesBetween(articleIDs: articleIDs, before: before, after: after) } - public func fetchUnreadArticlesBetween(_ webFeedIDs: Set, _ limit: Int?, _ before: Date?, _ after: Date?) throws -> Set
{ - return try articlesTable.fetchUnreadArticlesBetween(webFeedIDs, limit, before, after) + public func fetchUnreadArticlesBetween(_ feedIDs: Set, _ limit: Int?, _ before: Date?, _ after: Date?) throws -> Set
{ + return try articlesTable.fetchUnreadArticlesBetween(feedIDs, limit, before, after) } - public func fetchTodayArticles(_ webFeedIDs: Set, _ limit: Int?) throws -> Set
{ - return try articlesTable.fetchArticlesSince(webFeedIDs, todayCutoffDate(), limit) + public func fetchTodayArticles(_ feedIDs: Set, _ limit: Int?) throws -> Set
{ + return try articlesTable.fetchArticlesSince(feedIDs, todayCutoffDate(), limit) } - public func fetchStarredArticles(_ webFeedIDs: Set, _ limit: Int?) throws -> Set
{ - return try articlesTable.fetchStarredArticles(webFeedIDs, limit) + public func fetchStarredArticles(_ feedIDs: Set, _ limit: Int?) throws -> Set
{ + return try articlesTable.fetchStarredArticles(feedIDs, limit) } - public func fetchStarredArticlesCount(_ webFeedIDs: Set) throws -> Int { - return try articlesTable.fetchStarredArticlesCount(webFeedIDs) + public func fetchStarredArticlesCount(_ feedIDs: Set) throws -> Int { + return try articlesTable.fetchStarredArticlesCount(feedIDs) } - public func fetchArticlesMatching(_ searchString: String, _ webFeedIDs: Set) throws -> Set
{ - return try articlesTable.fetchArticlesMatching(searchString, webFeedIDs) + public func fetchArticlesMatching(_ searchString: String, _ feedIDs: Set) throws -> Set
{ + return try articlesTable.fetchArticlesMatching(searchString, feedIDs) } public func fetchArticlesMatchingWithArticleIDs(_ searchString: String, _ articleIDs: Set) throws -> Set
{ @@ -136,32 +136,32 @@ public final class ArticlesDatabase { // MARK: - Fetching Articles Async - public func fetchArticlesAsync(_ webFeedID: String, _ completion: @escaping ArticleSetResultBlock) { - articlesTable.fetchArticlesAsync(webFeedID, completion) + public func fetchArticlesAsync(_ feedID: String, _ completion: @escaping ArticleSetResultBlock) { + articlesTable.fetchArticlesAsync(feedID, completion) } - public func fetchArticlesAsync(_ webFeedIDs: Set, _ completion: @escaping ArticleSetResultBlock) { - articlesTable.fetchArticlesAsync(webFeedIDs, completion) + public func fetchArticlesAsync(_ feedIDs: Set, _ completion: @escaping ArticleSetResultBlock) { + articlesTable.fetchArticlesAsync(feedIDs, completion) } public func fetchArticlesAsync(articleIDs: Set, _ completion: @escaping ArticleSetResultBlock) { articlesTable.fetchArticlesAsync(articleIDs: articleIDs, completion) } - public func fetchUnreadArticlesAsync(_ webFeedIDs: Set, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { - articlesTable.fetchUnreadArticlesAsync(webFeedIDs, limit, completion) + public func fetchUnreadArticlesAsync(_ feedIDs: Set, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { + articlesTable.fetchUnreadArticlesAsync(feedIDs, limit, completion) } - public func fetchTodayArticlesAsync(_ webFeedIDs: Set, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { - articlesTable.fetchArticlesSinceAsync(webFeedIDs, todayCutoffDate(), limit, completion) + public func fetchTodayArticlesAsync(_ feedIDs: Set, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { + articlesTable.fetchArticlesSinceAsync(feedIDs, todayCutoffDate(), limit, completion) } - public func fetchedStarredArticlesAsync(_ webFeedIDs: Set, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { - articlesTable.fetchStarredArticlesAsync(webFeedIDs, limit, completion) + public func fetchedStarredArticlesAsync(_ feedIDs: Set, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { + articlesTable.fetchStarredArticlesAsync(feedIDs, limit, completion) } - public func fetchArticlesMatchingAsync(_ searchString: String, _ webFeedIDs: Set, _ completion: @escaping ArticleSetResultBlock) { - articlesTable.fetchArticlesMatchingAsync(searchString, webFeedIDs, completion) + public func fetchArticlesMatchingAsync(_ searchString: String, _ feedIDs: Set, _ completion: @escaping ArticleSetResultBlock) { + articlesTable.fetchArticlesMatchingAsync(searchString, feedIDs, completion) } public func fetchArticlesMatchingWithArticleIDsAsync(_ searchString: String, _ articleIDs: Set, _ completion: @escaping ArticleSetResultBlock) { @@ -191,9 +191,9 @@ public final class ArticlesDatabase { operationQueue.add(operation) } - /// Fetch non-zero unread counts for given webFeedIDs. - public func fetchUnreadCounts(for webFeedIDs: Set, _ completion: @escaping UnreadCountDictionaryCompletionBlock) { - let operation = FetchUnreadCountsForFeedsOperation(webFeedIDs: webFeedIDs, databaseQueue: queue) + /// Fetch non-zero unread counts for given feedIDs. + public func fetchUnreadCounts(for feedIDs: Set, _ completion: @escaping UnreadCountDictionaryCompletionBlock) { + let operation = FetchUnreadCountsForFeedsOperation(feedIDs: feedIDs, databaseQueue: queue) operation.completionBlock = { operation in let fetchOperation = operation as! FetchUnreadCountsForFeedsOperation completion(fetchOperation.result) @@ -201,30 +201,30 @@ public final class ArticlesDatabase { operationQueue.add(operation) } - public func fetchUnreadCountForToday(for webFeedIDs: Set, completion: @escaping SingleUnreadCountCompletionBlock) { - fetchUnreadCount(for: webFeedIDs, since: todayCutoffDate(), completion: completion) + public func fetchUnreadCountForToday(for feedIDs: Set, completion: @escaping SingleUnreadCountCompletionBlock) { + fetchUnreadCount(for: feedIDs, since: todayCutoffDate(), completion: completion) } - public func fetchUnreadCount(for webFeedIDs: Set, since: Date, completion: @escaping SingleUnreadCountCompletionBlock) { - articlesTable.fetchUnreadCount(webFeedIDs, since, completion) + public func fetchUnreadCount(for feedIDs: Set, since: Date, completion: @escaping SingleUnreadCountCompletionBlock) { + articlesTable.fetchUnreadCount(feedIDs, since, completion) } - public func fetchStarredAndUnreadCount(for webFeedIDs: Set, completion: @escaping SingleUnreadCountCompletionBlock) { - articlesTable.fetchStarredAndUnreadCount(webFeedIDs, completion) + public func fetchStarredAndUnreadCount(for feedIDs: Set, completion: @escaping SingleUnreadCountCompletionBlock) { + articlesTable.fetchStarredAndUnreadCount(feedIDs, completion) } // MARK: - Saving, Updating, and Deleting Articles /// Update articles and save new ones — for feed-based systems (local and iCloud). - public func update(with parsedItems: Set, webFeedID: String, deleteOlder: Bool, completion: @escaping UpdateArticlesCompletionBlock) { + public func update(with parsedItems: Set, feedID: String, deleteOlder: Bool, completion: @escaping UpdateArticlesCompletionBlock) { precondition(retentionStyle == .feedBased) - articlesTable.update(parsedItems, webFeedID, deleteOlder, completion) + articlesTable.update(parsedItems, feedID, deleteOlder, completion) } /// Update articles and save new ones — for sync systems (Feedbin, Feedly, etc.). - public func update(webFeedIDsAndItems: [String: Set], defaultRead: Bool, completion: @escaping UpdateArticlesCompletionBlock) { + public func update(feedIDsAndItems: [String: Set], defaultRead: Bool, completion: @escaping UpdateArticlesCompletionBlock) { precondition(retentionStyle == .syncSystem) - articlesTable.update(webFeedIDsAndItems, defaultRead, completion) + articlesTable.update(feedIDsAndItems, defaultRead, completion) } /// Delete articles @@ -301,11 +301,11 @@ public final class ArticlesDatabase { /// This prevents the database from growing forever. If we didn’t do this: /// 1) The database would grow to an inordinate size, and /// 2) the app would become very slow. - public func cleanupDatabaseAtStartup(subscribedToWebFeedIDs: Set) { + public func cleanupDatabaseAtStartup(subscribedToFeedIDs: Set) { if retentionStyle == .syncSystem { articlesTable.deleteOldArticles() } - articlesTable.deleteArticlesNotInSubscribedToFeedIDs(subscribedToWebFeedIDs) + articlesTable.deleteArticlesNotInSubscribedToFeedIDs(subscribedToFeedIDs) articlesTable.deleteOldStatuses() } diff --git a/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesTable.swift b/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesTable.swift index ac59619da..498bea55d 100644 --- a/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesTable.swift +++ b/ArticlesDatabase/Sources/ArticlesDatabase/ArticlesTable.swift @@ -48,20 +48,20 @@ final class ArticlesTable: DatabaseTable { // MARK: - Fetching Articles for Feed - func fetchArticles(_ webFeedID: String) throws -> Set
{ - return try fetchArticles{ self.fetchArticlesForFeedID(webFeedID, $0) } + func fetchArticles(_ feedID: String) throws -> Set
{ + return try fetchArticles{ self.fetchArticlesForFeedID(feedID, $0) } } - func fetchArticlesAsync(_ webFeedID: String, _ completion: @escaping ArticleSetResultBlock) { - fetchArticlesAsync({ self.fetchArticlesForFeedID(webFeedID, $0) }, completion) + func fetchArticlesAsync(_ feedID: String, _ completion: @escaping ArticleSetResultBlock) { + fetchArticlesAsync({ self.fetchArticlesForFeedID(feedID, $0) }, completion) } - func fetchArticles(_ webFeedIDs: Set) throws -> Set
{ - return try fetchArticles{ self.fetchArticles(webFeedIDs, $0) } + func fetchArticles(_ feedIDs: Set) throws -> Set
{ + return try fetchArticles{ self.fetchArticles(feedIDs, $0) } } - func fetchArticlesAsync(_ webFeedIDs: Set, _ completion: @escaping ArticleSetResultBlock) { - fetchArticlesAsync({ self.fetchArticles(webFeedIDs, $0) }, completion) + func fetchArticlesAsync(_ feedIDs: Set, _ completion: @escaping ArticleSetResultBlock) { + fetchArticlesAsync({ self.fetchArticles(feedIDs, $0) }, completion) } // MARK: - Fetching Articles by articleID @@ -80,40 +80,40 @@ final class ArticlesTable: DatabaseTable { // MARK: - Fetching Unread Articles - func fetchUnreadArticles(_ webFeedIDs: Set, _ limit: Int?) throws -> Set
{ - return try fetchArticles{ self.fetchUnreadArticles(webFeedIDs, limit, $0) } + func fetchUnreadArticles(_ feedIDs: Set, _ limit: Int?) throws -> Set
{ + return try fetchArticles{ self.fetchUnreadArticles(feedIDs, limit, $0) } } - func fetchUnreadArticlesBetween(_ webFeedIDs: Set, _ limit: Int?, _ before: Date?, _ after: Date?) throws -> Set
{ - return try fetchArticles{ self.fetchUnreadArticlesBetween(webFeedIDs, limit, $0, before, after) } + func fetchUnreadArticlesBetween(_ feedIDs: Set, _ limit: Int?, _ before: Date?, _ after: Date?) throws -> Set
{ + return try fetchArticles{ self.fetchUnreadArticlesBetween(feedIDs, limit, $0, before, after) } } - func fetchUnreadArticlesAsync(_ webFeedIDs: Set, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { - fetchArticlesAsync({ self.fetchUnreadArticles(webFeedIDs, limit, $0) }, completion) + func fetchUnreadArticlesAsync(_ feedIDs: Set, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { + fetchArticlesAsync({ self.fetchUnreadArticles(feedIDs, limit, $0) }, completion) } // MARK: - Fetching Today Articles - func fetchArticlesSince(_ webFeedIDs: Set, _ cutoffDate: Date, _ limit: Int?) throws -> Set
{ - return try fetchArticles{ self.fetchArticlesSince(webFeedIDs, cutoffDate, limit, $0) } + func fetchArticlesSince(_ feedIDs: Set, _ cutoffDate: Date, _ limit: Int?) throws -> Set
{ + return try fetchArticles{ self.fetchArticlesSince(feedIDs, cutoffDate, limit, $0) } } - func fetchArticlesSinceAsync(_ webFeedIDs: Set, _ cutoffDate: Date, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { - fetchArticlesAsync({ self.fetchArticlesSince(webFeedIDs, cutoffDate, limit, $0) }, completion) + func fetchArticlesSinceAsync(_ feedIDs: Set, _ cutoffDate: Date, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { + fetchArticlesAsync({ self.fetchArticlesSince(feedIDs, cutoffDate, limit, $0) }, completion) } // MARK: - Fetching Starred Articles - func fetchStarredArticles(_ webFeedIDs: Set, _ limit: Int?) throws -> Set
{ - return try fetchArticles{ self.fetchStarredArticles(webFeedIDs, limit, $0) } + func fetchStarredArticles(_ feedIDs: Set, _ limit: Int?) throws -> Set
{ + return try fetchArticles{ self.fetchStarredArticles(feedIDs, limit, $0) } } - func fetchStarredArticlesAsync(_ webFeedIDs: Set, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { - fetchArticlesAsync({ self.fetchStarredArticles(webFeedIDs, limit, $0) }, completion) + func fetchStarredArticlesAsync(_ feedIDs: Set, _ limit: Int?, _ completion: @escaping ArticleSetResultBlock) { + fetchArticlesAsync({ self.fetchStarredArticles(feedIDs, limit, $0) }, completion) } - func fetchStarredArticlesCount(_ webFeedIDs: Set) throws -> Int { - return try fetchArticlesCount{ self.fetchStarredArticlesCount(webFeedIDs, $0) } + func fetchStarredArticlesCount(_ feedIDs: Set) throws -> Int { + return try fetchArticlesCount{ self.fetchStarredArticlesCount(feedIDs, $0) } } // MARK: - Fetching Search Articles @@ -137,9 +137,9 @@ final class ArticlesTable: DatabaseTable { return articles } - func fetchArticlesMatching(_ searchString: String, _ webFeedIDs: Set) throws -> Set
{ + func fetchArticlesMatching(_ searchString: String, _ feedIDs: Set) throws -> Set
{ var articles = try fetchArticlesMatching(searchString) - articles = articles.filter{ webFeedIDs.contains($0.webFeedID) } + articles = articles.filter{ feedIDs.contains($0.webFeedID) } return articles } @@ -149,8 +149,8 @@ final class ArticlesTable: DatabaseTable { return articles } - func fetchArticlesMatchingAsync(_ searchString: String, _ webFeedIDs: Set, _ completion: @escaping ArticleSetResultBlock) { - fetchArticlesAsync({ self.fetchArticlesMatching(searchString, webFeedIDs, $0) }, completion) + func fetchArticlesMatchingAsync(_ searchString: String, _ feedIDs: Set, _ completion: @escaping ArticleSetResultBlock) { + fetchArticlesAsync({ self.fetchArticlesMatching(searchString, feedIDs, $0) }, completion) } func fetchArticlesMatchingWithArticleIDsAsync(_ searchString: String, _ articleIDs: Set, _ completion: @escaping ArticleSetResultBlock) { @@ -203,7 +203,7 @@ final class ArticlesTable: DatabaseTable { // MARK: - Updating and Deleting - func update(_ parsedItems: Set, _ webFeedID: String, _ deleteOlder: Bool, _ completion: @escaping UpdateArticlesCompletionBlock) { + func update(_ parsedItems: Set, _ feedID: String, _ deleteOlder: Bool, _ completion: @escaping UpdateArticlesCompletionBlock) { precondition(retentionStyle == .feedBased) if parsedItems.isEmpty { callUpdateArticlesCompletionBlock(nil, nil, nil, completion) @@ -228,13 +228,13 @@ final class ArticlesTable: DatabaseTable { let statusesDictionary = self.statusesTable.ensureStatusesForArticleIDs(articleIDs, false, database) //1 assert(statusesDictionary.count == articleIDs.count) - let incomingArticles = Article.articlesWithParsedItems(parsedItems, webFeedID, self.accountID, statusesDictionary) //2 + let incomingArticles = Article.articlesWithParsedItems(parsedItems, feedID, self.accountID, statusesDictionary) //2 if incomingArticles.isEmpty { self.callUpdateArticlesCompletionBlock(nil, nil, nil, completion) return } - let fetchedArticles = self.fetchArticlesForFeedID(webFeedID, database) //4 + let fetchedArticles = self.fetchArticlesForFeedID(feedID, database) //4 let fetchedArticlesDictionary = fetchedArticles.dictionary() let newArticles = self.findAndSaveNewArticles(incomingArticles, fetchedArticlesDictionary, database) //5 @@ -283,9 +283,9 @@ final class ArticlesTable: DatabaseTable { } } - func update(_ webFeedIDsAndItems: [String: Set], _ read: Bool, _ completion: @escaping UpdateArticlesCompletionBlock) { + func update(_ feedIDsAndItems: [String: Set], _ read: Bool, _ completion: @escaping UpdateArticlesCompletionBlock) { precondition(retentionStyle == .syncSystem) - if webFeedIDsAndItems.isEmpty { + if feedIDsAndItems.isEmpty { callUpdateArticlesCompletionBlock(nil, nil, nil, completion) return } @@ -303,14 +303,14 @@ final class ArticlesTable: DatabaseTable { func makeDatabaseCalls(_ database: FMDatabase) { var articleIDs = Set() - for (_, parsedItems) in webFeedIDsAndItems { + for (_, parsedItems) in feedIDsAndItems { articleIDs.formUnion(parsedItems.articleIDs()) } let statusesDictionary = self.statusesTable.ensureStatusesForArticleIDs(articleIDs, read, database) //1 assert(statusesDictionary.count == articleIDs.count) - let allIncomingArticles = Article.articlesWithWebFeedIDsAndItems(webFeedIDsAndItems, self.accountID, statusesDictionary) //2 + let allIncomingArticles = Article.articlesWithFeedIDsAndItems(feedIDsAndItems, self.accountID, statusesDictionary) //2 if allIncomingArticles.isEmpty { self.callUpdateArticlesCompletionBlock(nil, nil, nil, completion) return @@ -379,9 +379,9 @@ final class ArticlesTable: DatabaseTable { // MARK: - Unread Counts - func fetchUnreadCount(_ webFeedIDs: Set, _ since: Date, _ completion: @escaping SingleUnreadCountCompletionBlock) { + func fetchUnreadCount(_ feedIDs: Set, _ since: Date, _ completion: @escaping SingleUnreadCountCompletionBlock) { // Get unread count for today, for instance. - if webFeedIDs.isEmpty { + if feedIDs.isEmpty { completion(.success(0)) return } @@ -389,11 +389,11 @@ final class ArticlesTable: DatabaseTable { queue.runInDatabase { databaseResult in func makeDatabaseCalls(_ database: FMDatabase) { - let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(webFeedIDs.count))! + let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))! let sql = "select count(*) from articles natural join statuses where feedID in \(placeholders) and (datePublished > ? or (datePublished is null and dateArrived > ?)) and read=0;" var parameters = [Any]() - parameters += Array(webFeedIDs) as [Any] + parameters += Array(feedIDs) as [Any] parameters += [since] as [Any] parameters += [since] as [Any] @@ -415,8 +415,8 @@ final class ArticlesTable: DatabaseTable { } } - func fetchStarredAndUnreadCount(_ webFeedIDs: Set, _ completion: @escaping SingleUnreadCountCompletionBlock) { - if webFeedIDs.isEmpty { + func fetchStarredAndUnreadCount(_ feedIDs: Set, _ completion: @escaping SingleUnreadCountCompletionBlock) { + if feedIDs.isEmpty { completion(.success(0)) return } @@ -424,9 +424,9 @@ final class ArticlesTable: DatabaseTable { queue.runInDatabase { databaseResult in func makeDatabaseCalls(_ database: FMDatabase) { - let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(webFeedIDs.count))! + let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))! let sql = "select count(*) from articles natural join statuses where feedID in \(placeholders) and read=0 and starred=1;" - let parameters = Array(webFeedIDs) as [Any] + let parameters = Array(feedIDs) as [Any] let unreadCount = self.numberWithSQLAndParameters(sql, parameters, in: database) @@ -617,16 +617,16 @@ final class ArticlesTable: DatabaseTable { /// Delete articles from feeds that are no longer in the current set of subscribed-to feeds. /// This deletes from the articles and articleStatuses tables, /// and, via a trigger, it also deletes from the search index. - func deleteArticlesNotInSubscribedToFeedIDs(_ webFeedIDs: Set) { - if webFeedIDs.isEmpty { + func deleteArticlesNotInSubscribedToFeedIDs(_ feedIDs: Set) { + if feedIDs.isEmpty { return } queue.runInDatabase { databaseResult in func makeDatabaseCalls(_ database: FMDatabase) { - let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(webFeedIDs.count))! + let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))! let sql = "select articleID from articles where feedID not in \(placeholders);" - let parameters = Array(webFeedIDs) as [Any] + let parameters = Array(feedIDs) as [Any] guard let resultSet = database.executeQuery(sql, withArgumentsIn: parameters) else { return } @@ -828,24 +828,24 @@ private extension ArticlesTable { return articlesWithResultSet(resultSet, database) } - func fetchArticles(_ webFeedIDs: Set, _ database: FMDatabase) -> Set
{ + func fetchArticles(_ feedIDs: Set, _ database: FMDatabase) -> Set
{ // select * from articles natural join statuses where feedID in ('http://ranchero.com/xml/rss.xml') and read=0 - if webFeedIDs.isEmpty { + if feedIDs.isEmpty { return Set
() } - let parameters = webFeedIDs.map { $0 as AnyObject } - let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(webFeedIDs.count))! + let parameters = feedIDs.map { $0 as AnyObject } + let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))! let whereClause = "feedID in \(placeholders)" return fetchArticlesWithWhereClause(database, whereClause: whereClause, parameters: parameters) } - func fetchUnreadArticles(_ webFeedIDs: Set, _ limit: Int?, _ database: FMDatabase) -> Set
{ + func fetchUnreadArticles(_ feedIDs: Set, _ limit: Int?, _ database: FMDatabase) -> Set
{ // select * from articles natural join statuses where feedID in ('http://ranchero.com/xml/rss.xml') and read=0 - if webFeedIDs.isEmpty { + if feedIDs.isEmpty { return Set
() } - let parameters = webFeedIDs.map { $0 as AnyObject } - let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(webFeedIDs.count))! + let parameters = feedIDs.map { $0 as AnyObject } + let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))! var whereClause = "feedID in \(placeholders) and read=0" if let limit = limit { whereClause.append(" order by coalesce(datePublished, dateModified, dateArrived) desc limit \(limit)") @@ -853,14 +853,14 @@ private extension ArticlesTable { return fetchArticlesWithWhereClause(database, whereClause: whereClause, parameters: parameters) } - func fetchUnreadArticlesBetween(_ webFeedIDs: Set, _ limit: Int?, _ database: FMDatabase, _ before: Date?, _ after: Date?) -> Set
{ + func fetchUnreadArticlesBetween(_ feedIDs: Set, _ limit: Int?, _ database: FMDatabase, _ before: Date?, _ after: Date?) -> Set
{ // select * from articles natural join statuses where feedID in ('http://ranchero.com/xml/rss.xml') and read=0 - if webFeedIDs.isEmpty { + if feedIDs.isEmpty { return Set
() } - var parameters = webFeedIDs.map { $0 as AnyObject } + var parameters = feedIDs.map { $0 as AnyObject } - let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(webFeedIDs.count))! + let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))! var whereClause = "feedID in \(placeholders) and read=0" if let before = before { @@ -877,8 +877,8 @@ private extension ArticlesTable { return fetchArticlesWithWhereClause(database, whereClause: whereClause, parameters: parameters) } - func fetchArticlesForFeedID(_ webFeedID: String, _ database: FMDatabase) -> Set
{ - return fetchArticlesWithWhereClause(database, whereClause: "articles.feedID = ?", parameters: [webFeedID as AnyObject]) + func fetchArticlesForFeedID(_ feedID: String, _ database: FMDatabase) -> Set
{ + return fetchArticlesWithWhereClause(database, whereClause: "articles.feedID = ?", parameters: [feedID as AnyObject]) } func fetchArticles(articleIDs: Set, _ database: FMDatabase) -> Set
{ @@ -911,15 +911,15 @@ private extension ArticlesTable { return fetchArticlesWithWhereClause(database, whereClause: whereClause, parameters: parameters) } - func fetchArticlesSince(_ webFeedIDs: Set, _ cutoffDate: Date, _ limit: Int?, _ database: FMDatabase) -> Set
{ + func fetchArticlesSince(_ feedIDs: Set, _ cutoffDate: Date, _ limit: Int?, _ database: FMDatabase) -> Set
{ // select * from articles natural join statuses where feedID in ('http://ranchero.com/xml/rss.xml') and (datePublished > ? || (datePublished is null and dateArrived > ?) // // datePublished may be nil, so we fall back to dateArrived. - if webFeedIDs.isEmpty { + if feedIDs.isEmpty { return Set
() } - let parameters = webFeedIDs.map { $0 as AnyObject } + [cutoffDate as AnyObject, cutoffDate as AnyObject] - let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(webFeedIDs.count))! + let parameters = feedIDs.map { $0 as AnyObject } + [cutoffDate as AnyObject, cutoffDate as AnyObject] + let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))! var whereClause = "feedID in \(placeholders) and (datePublished > ? or (datePublished is null and dateArrived > ?))" if let limit = limit { whereClause.append(" order by coalesce(datePublished, dateModified, dateArrived) desc limit \(limit)") @@ -927,13 +927,13 @@ private extension ArticlesTable { return fetchArticlesWithWhereClause(database, whereClause: whereClause, parameters: parameters) } - func fetchStarredArticles(_ webFeedIDs: Set, _ limit: Int?, _ database: FMDatabase) -> Set
{ + func fetchStarredArticles(_ feedIDs: Set, _ limit: Int?, _ database: FMDatabase) -> Set
{ // select * from articles natural join statuses where feedID in ('http://ranchero.com/xml/rss.xml') and starred=1; - if webFeedIDs.isEmpty { + if feedIDs.isEmpty { return Set
() } - let parameters = webFeedIDs.map { $0 as AnyObject } - let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(webFeedIDs.count))! + let parameters = feedIDs.map { $0 as AnyObject } + let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))! var whereClause = "feedID in \(placeholders) and starred=1" if let limit = limit { whereClause.append(" order by coalesce(datePublished, dateModified, dateArrived) desc limit \(limit)") @@ -941,21 +941,21 @@ private extension ArticlesTable { return fetchArticlesWithWhereClause(database, whereClause: whereClause, parameters: parameters) } - func fetchStarredArticlesCount(_ webFeedIDs: Set, _ database: FMDatabase) -> Int { + func fetchStarredArticlesCount(_ feedIDs: Set, _ database: FMDatabase) -> Int { // select count from articles natural join statuses where feedID in ('http://ranchero.com/xml/rss.xml') and starred=1; - if webFeedIDs.isEmpty { + if feedIDs.isEmpty { return 0 } - let parameters = webFeedIDs.map { $0 as AnyObject } - let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(webFeedIDs.count))! + let parameters = feedIDs.map { $0 as AnyObject } + let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))! let whereClause = "feedID in \(placeholders) and starred=1" return fetchArticleCountsWithWhereClause(database, whereClause: whereClause, parameters: parameters) } - func fetchArticlesMatching(_ searchString: String, _ webFeedIDs: Set, _ database: FMDatabase) -> Set
{ + func fetchArticlesMatching(_ searchString: String, _ feedIDs: Set, _ database: FMDatabase) -> Set
{ let articles = fetchArticlesMatching(searchString, database) // TODO: include the feedIDs in the SQL rather than filtering here. - return articles.filter{ webFeedIDs.contains($0.webFeedID) } + return articles.filter{ feedIDs.contains($0.webFeedID) } } func fetchArticlesMatchingWithArticleIDs(_ searchString: String, _ articleIDs: Set, _ database: FMDatabase) -> Set
{ diff --git a/ArticlesDatabase/Sources/ArticlesDatabase/Extensions/Article+Database.swift b/ArticlesDatabase/Sources/ArticlesDatabase/Extensions/Article+Database.swift index 30ac2bfd3..1bf056143 100644 --- a/ArticlesDatabase/Sources/ArticlesDatabase/Extensions/Article+Database.swift +++ b/ArticlesDatabase/Sources/ArticlesDatabase/Extensions/Article+Database.swift @@ -117,22 +117,22 @@ extension Article { return Date().addingTimeInterval(60 * 60 * 24) // Allow dates up to about 24 hours ahead of now } - static func articlesWithWebFeedIDsAndItems(_ webFeedIDsAndItems: [String: Set], _ accountID: String, _ statusesDictionary: [String: ArticleStatus]) -> Set
{ + static func articlesWithFeedIDsAndItems(_ feedIDsAndItems: [String: Set], _ accountID: String, _ statusesDictionary: [String: ArticleStatus]) -> Set
{ let maximumDateAllowed = _maximumDateAllowed() var feedArticles = Set
() - for (webFeedID, parsedItems) in webFeedIDsAndItems { + for (feedID, parsedItems) in feedIDsAndItems { for parsedItem in parsedItems { let status = statusesDictionary[parsedItem.articleID]! - let article = Article(parsedItem: parsedItem, maximumDateAllowed: maximumDateAllowed, accountID: accountID, webFeedID: webFeedID, status: status) + let article = Article(parsedItem: parsedItem, maximumDateAllowed: maximumDateAllowed, accountID: accountID, webFeedID: feedID, status: status) feedArticles.insert(article) } } return feedArticles } - static func articlesWithParsedItems(_ parsedItems: Set, _ webFeedID: String, _ accountID: String, _ statusesDictionary: [String: ArticleStatus]) -> Set
{ + static func articlesWithParsedItems(_ parsedItems: Set, _ feedID: String, _ accountID: String, _ statusesDictionary: [String: ArticleStatus]) -> Set
{ let maximumDateAllowed = _maximumDateAllowed() - return Set(parsedItems.map{ Article(parsedItem: $0, maximumDateAllowed: maximumDateAllowed, accountID: accountID, webFeedID: webFeedID, status: statusesDictionary[$0.articleID]!) }) + return Set(parsedItems.map{ Article(parsedItem: $0, maximumDateAllowed: maximumDateAllowed, accountID: accountID, webFeedID: feedID, status: statusesDictionary[$0.articleID]!) }) } } diff --git a/ArticlesDatabase/Sources/ArticlesDatabase/Extensions/ParsedArticle+Database.swift b/ArticlesDatabase/Sources/ArticlesDatabase/Extensions/ParsedArticle+Database.swift index e59539d11..271876057 100644 --- a/ArticlesDatabase/Sources/ArticlesDatabase/Extensions/ParsedArticle+Database.swift +++ b/ArticlesDatabase/Sources/ArticlesDatabase/Extensions/ParsedArticle+Database.swift @@ -17,6 +17,6 @@ extension ParsedItem { return s } // Must be same calculation as for Article. - return Article.calculatedArticleID(webFeedID: feedURL, uniqueID: uniqueID) + return Article.calculatedArticleID(feedID: feedURL, uniqueID: uniqueID) } } diff --git a/ArticlesDatabase/Sources/ArticlesDatabase/Operations/FetchAllUnreadCountsOperation.swift b/ArticlesDatabase/Sources/ArticlesDatabase/Operations/FetchAllUnreadCountsOperation.swift index bad3e2e1f..2b49db38f 100644 --- a/ArticlesDatabase/Sources/ArticlesDatabase/Operations/FetchAllUnreadCountsOperation.swift +++ b/ArticlesDatabase/Sources/ArticlesDatabase/Operations/FetchAllUnreadCountsOperation.swift @@ -63,8 +63,8 @@ private extension FetchAllUnreadCountsOperation { return } let unreadCount = resultSet.long(forColumnIndex: 1) - if let webFeedID = resultSet.string(forColumnIndex: 0) { - unreadCountDictionary[webFeedID] = unreadCount + if let feedID = resultSet.string(forColumnIndex: 0) { + unreadCountDictionary[feedID] = unreadCount } } resultSet.close() diff --git a/ArticlesDatabase/Sources/ArticlesDatabase/Operations/FetchUnreadCountsForFeedsOperation.swift b/ArticlesDatabase/Sources/ArticlesDatabase/Operations/FetchUnreadCountsForFeedsOperation.swift index 3a560a94d..c3bcff808 100644 --- a/ArticlesDatabase/Sources/ArticlesDatabase/Operations/FetchUnreadCountsForFeedsOperation.swift +++ b/ArticlesDatabase/Sources/ArticlesDatabase/Operations/FetchUnreadCountsForFeedsOperation.swift @@ -24,10 +24,10 @@ public final class FetchUnreadCountsForFeedsOperation: MainThreadOperation { public var completionBlock: MainThreadOperation.MainThreadOperationCompletionBlock? private let queue: DatabaseQueue - private let webFeedIDs: Set + private let feedIDs: Set - init(webFeedIDs: Set, databaseQueue: DatabaseQueue) { - self.webFeedIDs = webFeedIDs + init(feedIDs: Set, databaseQueue: DatabaseQueue) { + self.feedIDs = feedIDs self.queue = databaseQueue } @@ -51,10 +51,10 @@ public final class FetchUnreadCountsForFeedsOperation: MainThreadOperation { private extension FetchUnreadCountsForFeedsOperation { func fetchUnreadCounts(_ database: FMDatabase) { - let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(webFeedIDs.count))! + let placeholders = NSString.rs_SQLValueList(withPlaceholders: UInt(feedIDs.count))! let sql = "select distinct feedID, count(*) from articles natural join statuses where feedID in \(placeholders) and read=0 group by feedID;" - let parameters = Array(webFeedIDs) as [Any] + let parameters = Array(feedIDs) as [Any] guard let resultSet = database.executeQuery(sql, withArgumentsIn: parameters) else { informOperationDelegateOfCompletion() @@ -74,8 +74,8 @@ private extension FetchUnreadCountsForFeedsOperation { return } let unreadCount = resultSet.long(forColumnIndex: 1) - if let webFeedID = resultSet.string(forColumnIndex: 0) { - unreadCountDictionary[webFeedID] = unreadCount + if let feedID = resultSet.string(forColumnIndex: 0) { + unreadCountDictionary[feedID] = unreadCount } } resultSet.close()