Change markAndFetchNew to just mark and get rid of the return value
which wasn’t used anywhere.
This commit is contained in:
parent
e58f8ada42
commit
5c6e5807d9
|
@ -868,44 +868,43 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
|||
/// Mark articleIDs statuses based on statusKey and flag.
|
||||
/// Will create statuses in the database and in memory as needed. Sends a .StatusesDidChange notification.
|
||||
/// Returns a set of new article statuses.
|
||||
func markAndFetchNew(articleIDs: Set<String>, statusKey: ArticleStatus.Key, flag: Bool, completion: ArticleIDsCompletionBlock? = nil) {
|
||||
func mark(articleIDs: Set<String>, statusKey: ArticleStatus.Key, flag: Bool, completion: DatabaseCompletionBlock? = nil) {
|
||||
guard !articleIDs.isEmpty else {
|
||||
completion?(.success(Set<String>()))
|
||||
completion?(nil)
|
||||
return
|
||||
}
|
||||
database.markAndFetchNew(articleIDs: articleIDs, statusKey: statusKey, flag: flag) { result in
|
||||
switch result {
|
||||
case .success(let newArticleStatusIDs):
|
||||
database.mark(articleIDs: articleIDs, statusKey: statusKey, flag: flag) { error in
|
||||
if let error {
|
||||
completion?(error)
|
||||
} else {
|
||||
self.noteStatusesForArticleIDsDidChange(articleIDs: articleIDs, statusKey: statusKey, flag: flag)
|
||||
completion?(.success(newArticleStatusIDs))
|
||||
case .failure(let databaseError):
|
||||
completion?(.failure(databaseError))
|
||||
completion?(nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Mark articleIDs as read. Will create statuses in the database and in memory as needed. Sends a .StatusesDidChange notification.
|
||||
/// Returns a set of new article statuses.
|
||||
func markAsRead(_ articleIDs: Set<String>, completion: ArticleIDsCompletionBlock? = nil) {
|
||||
markAndFetchNew(articleIDs: articleIDs, statusKey: .read, flag: true, completion: completion)
|
||||
func markAsRead(_ articleIDs: Set<String>, completion: DatabaseCompletionBlock? = nil) {
|
||||
mark(articleIDs: articleIDs, statusKey: .read, flag: true, completion: completion)
|
||||
}
|
||||
|
||||
/// Mark articleIDs as unread. Will create statuses in the database and in memory as needed. Sends a .StatusesDidChange notification.
|
||||
/// Returns a set of new article statuses.
|
||||
func markAsUnread(_ articleIDs: Set<String>, completion: ArticleIDsCompletionBlock? = nil) {
|
||||
markAndFetchNew(articleIDs: articleIDs, statusKey: .read, flag: false, completion: completion)
|
||||
func markAsUnread(_ articleIDs: Set<String>, completion: DatabaseCompletionBlock? = nil) {
|
||||
mark(articleIDs: articleIDs, statusKey: .read, flag: false, completion: completion)
|
||||
}
|
||||
|
||||
/// Mark articleIDs as starred. Will create statuses in the database and in memory as needed. Sends a .StatusesDidChange notification.
|
||||
/// Returns a set of new article statuses.
|
||||
func markAsStarred(_ articleIDs: Set<String>, completion: ArticleIDsCompletionBlock? = nil) {
|
||||
markAndFetchNew(articleIDs: articleIDs, statusKey: .starred, flag: true, completion: completion)
|
||||
func markAsStarred(_ articleIDs: Set<String>, completion: DatabaseCompletionBlock? = nil) {
|
||||
mark(articleIDs: articleIDs, statusKey: .starred, flag: true, completion: completion)
|
||||
}
|
||||
|
||||
/// Mark articleIDs as unstarred. Will create statuses in the database and in memory as needed. Sends a .StatusesDidChange notification.
|
||||
/// Returns a set of new article statuses.
|
||||
func markAsUnstarred(_ articleIDs: Set<String>, completion: ArticleIDsCompletionBlock? = nil) {
|
||||
markAndFetchNew(articleIDs: articleIDs, statusKey: .starred, flag: false, completion: completion)
|
||||
func markAsUnstarred(_ articleIDs: Set<String>, completion: DatabaseCompletionBlock? = nil) {
|
||||
mark(articleIDs: articleIDs, statusKey: .starred, flag: false, completion: completion)
|
||||
}
|
||||
|
||||
// Delete the articles associated with the given set of articleIDs
|
||||
|
|
|
@ -99,9 +99,9 @@ private extension CloudKitArticlesZoneDelegate {
|
|||
let group = DispatchGroup()
|
||||
|
||||
group.enter()
|
||||
account?.markAsUnread(updateableUnreadArticleIDs) { result in
|
||||
account?.markAsUnread(updateableUnreadArticleIDs) { databaseError in
|
||||
MainActor.assumeIsolated {
|
||||
if case .failure(let databaseError) = result {
|
||||
if let databaseError {
|
||||
errorOccurred = true
|
||||
os_log(.error, log: self.log, "Error occurred while storing unread statuses: %@", databaseError.localizedDescription)
|
||||
}
|
||||
|
@ -110,9 +110,9 @@ private extension CloudKitArticlesZoneDelegate {
|
|||
}
|
||||
|
||||
group.enter()
|
||||
account?.markAsRead(updateableReadArticleIDs) { result in
|
||||
account?.markAsRead(updateableReadArticleIDs) { databaseError in
|
||||
MainActor.assumeIsolated {
|
||||
if case .failure(let databaseError) = result {
|
||||
if let databaseError {
|
||||
errorOccurred = true
|
||||
os_log(.error, log: self.log, "Error occurred while storing read statuses: %@", databaseError.localizedDescription)
|
||||
}
|
||||
|
@ -121,9 +121,9 @@ private extension CloudKitArticlesZoneDelegate {
|
|||
}
|
||||
|
||||
group.enter()
|
||||
account?.markAsUnstarred(updateableUnstarredArticleIDs) { result in
|
||||
account?.markAsUnstarred(updateableUnstarredArticleIDs) { databaseError in
|
||||
MainActor.assumeIsolated {
|
||||
if case .failure(let databaseError) = result {
|
||||
if let databaseError {
|
||||
errorOccurred = true
|
||||
os_log(.error, log: self.log, "Error occurred while storing unstarred statuses: %@", databaseError.localizedDescription)
|
||||
}
|
||||
|
@ -132,9 +132,9 @@ private extension CloudKitArticlesZoneDelegate {
|
|||
}
|
||||
|
||||
group.enter()
|
||||
account?.markAsStarred(updateableStarredArticleIDs) { result in
|
||||
account?.markAsStarred(updateableStarredArticleIDs) { databaseError in
|
||||
MainActor.assumeIsolated {
|
||||
if case .failure(let databaseError) = result {
|
||||
if let databaseError {
|
||||
errorOccurred = true
|
||||
os_log(.error, log: self.log, "Error occurred while storing starred statuses: %@", databaseError.localizedDescription)
|
||||
}
|
||||
|
|
|
@ -125,8 +125,8 @@ final class FeedlyIngestStarredArticleIdsOperation: FeedlyOperation {
|
|||
let results = StarredStatusResults()
|
||||
|
||||
group.enter()
|
||||
account.markAsStarred(remoteStarredArticleIDs) { result in
|
||||
if case .failure(let error) = result {
|
||||
account.markAsStarred(remoteStarredArticleIDs) { error in
|
||||
if let error {
|
||||
results.markAsStarredError = error
|
||||
}
|
||||
group.leave()
|
||||
|
@ -134,8 +134,8 @@ final class FeedlyIngestStarredArticleIdsOperation: FeedlyOperation {
|
|||
|
||||
let deltaUnstarredArticleIDs = localStarredArticleIDs.subtracting(remoteStarredArticleIDs)
|
||||
group.enter()
|
||||
account.markAsUnstarred(deltaUnstarredArticleIDs) { result in
|
||||
if case .failure(let error) = result {
|
||||
account.markAsUnstarred(deltaUnstarredArticleIDs) { error in
|
||||
if let error {
|
||||
results.markAsUnstarredError = error
|
||||
}
|
||||
group.leave()
|
||||
|
|
|
@ -125,8 +125,8 @@ final class FeedlyIngestUnreadArticleIdsOperation: FeedlyOperation {
|
|||
let results = ReadStatusResults()
|
||||
|
||||
group.enter()
|
||||
account.markAsUnread(remoteUnreadArticleIDs) { result in
|
||||
if case .failure(let error) = result {
|
||||
account.markAsUnread(remoteUnreadArticleIDs) { error in
|
||||
if let error {
|
||||
results.markAsUnreadError = error
|
||||
}
|
||||
group.leave()
|
||||
|
@ -134,8 +134,8 @@ final class FeedlyIngestUnreadArticleIdsOperation: FeedlyOperation {
|
|||
|
||||
let articleIDsToMarkRead = localUnreadArticleIDs.subtracting(remoteUnreadArticleIDs)
|
||||
group.enter()
|
||||
account.markAsRead(articleIDsToMarkRead) { result in
|
||||
if case .failure(let error) = result {
|
||||
account.markAsRead(articleIDsToMarkRead) { error in
|
||||
if let error {
|
||||
results.markAsReadError = error
|
||||
}
|
||||
group.leave()
|
||||
|
|
|
@ -255,12 +255,12 @@ public actor ArticlesDatabase {
|
|||
return articlesTable.mark(articles: articles, statusKey: statusKey, flag: flag, database: database)
|
||||
}
|
||||
|
||||
public func markAndFetchNew(articleIDs: Set<String>, statusKey: ArticleStatus.Key, flag: Bool) throws -> Set<String> {
|
||||
public func mark(articleIDs: Set<String>, statusKey: ArticleStatus.Key, flag: Bool) throws {
|
||||
|
||||
guard let database else {
|
||||
throw DatabaseError.suspended
|
||||
}
|
||||
return articlesTable.markAndFetchNew(articleIDs: articleIDs, statusKey: statusKey, flag: flag, database: database)
|
||||
articlesTable.mark(articleIDs: articleIDs, statusKey: statusKey, flag: flag, database: database)
|
||||
}
|
||||
|
||||
/// Create statuses for specified articleIDs. For existing statuses, don’t do anything.
|
||||
|
|
|
@ -304,14 +304,14 @@ public extension ArticlesDatabase {
|
|||
}
|
||||
}
|
||||
|
||||
nonisolated func markAndFetchNew(articleIDs: Set<String>, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping ArticleIDsCompletionBlock) {
|
||||
nonisolated func mark(articleIDs: Set<String>, statusKey: ArticleStatus.Key, flag: Bool, completion: @escaping DatabaseCompletionBlock) {
|
||||
|
||||
Task {
|
||||
do {
|
||||
let statuses = try await markAndFetchNew(articleIDs: articleIDs, statusKey: statusKey, flag: flag)
|
||||
callArticleIDsCompletion(completion, .success(statuses))
|
||||
try await mark(articleIDs: articleIDs, statusKey: statusKey, flag: flag)
|
||||
callDatabaseCompletion(completion)
|
||||
} catch {
|
||||
callArticleIDsCompletion(completion, .failure(.suspended))
|
||||
callDatabaseCompletion(completion, .suspended)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -368,10 +368,9 @@ final class ArticlesTable {
|
|||
return statuses
|
||||
}
|
||||
|
||||
func markAndFetchNew(articleIDs: Set<String>, statusKey: ArticleStatus.Key, flag: Bool, database: FMDatabase) -> Set<String> {
|
||||
func mark(articleIDs: Set<String>, statusKey: ArticleStatus.Key, flag: Bool, database: FMDatabase) {
|
||||
|
||||
let newStatusIDs = statusesTable.markAndFetchNew(articleIDs, statusKey, flag, database)
|
||||
return newStatusIDs
|
||||
statusesTable.mark(articleIDs, statusKey, flag, database)
|
||||
}
|
||||
|
||||
/// Create statuses for specified articleIDs. For existing statuses, don’t do anything.
|
||||
|
|
|
@ -81,11 +81,10 @@ final class StatusesTable {
|
|||
return updatedStatuses
|
||||
}
|
||||
|
||||
func markAndFetchNew(_ articleIDs: Set<String>, _ statusKey: ArticleStatus.Key, _ flag: Bool, _ database: FMDatabase) -> Set<String> {
|
||||
let (statusesDictionary, newStatusIDs) = ensureStatusesForArticleIDs(articleIDs, flag, database)
|
||||
func mark(_ articleIDs: Set<String>, _ statusKey: ArticleStatus.Key, _ flag: Bool, _ database: FMDatabase) {
|
||||
let (statusesDictionary, _) = ensureStatusesForArticleIDs(articleIDs, flag, database)
|
||||
let statuses = Set(statusesDictionary.values)
|
||||
mark(statuses, statusKey, flag, database)
|
||||
return newStatusIDs
|
||||
}
|
||||
|
||||
// MARK: - Fetching
|
||||
|
|
Loading…
Reference in New Issue