Restrict the delete retention policy for synchronized records
This commit is contained in:
parent
d69b313525
commit
ffa152fe64
@ -743,12 +743,12 @@ public final class Account: DisplayNameProvider, UnreadCountProvider, Container,
|
|||||||
update(webFeed.webFeedID, with: parsedItems, completion: completion)
|
update(webFeed.webFeedID, with: parsedItems, completion: completion)
|
||||||
}
|
}
|
||||||
|
|
||||||
func update(_ webFeedID: String, with parsedItems: Set<ParsedItem>, completion: @escaping UpdateArticlesCompletionBlock) {
|
func update(_ webFeedID: String, with parsedItems: Set<ParsedItem>, deleteOlder: Bool = true, completion: @escaping UpdateArticlesCompletionBlock) {
|
||||||
// Used only by an On My Mac or iCloud account.
|
// Used only by an On My Mac or iCloud account.
|
||||||
precondition(Thread.isMainThread)
|
precondition(Thread.isMainThread)
|
||||||
precondition(type == .onMyMac || type == .cloudKit)
|
precondition(type == .onMyMac || type == .cloudKit)
|
||||||
|
|
||||||
database.update(with: parsedItems, webFeedID: webFeedID) { updateArticlesResult in
|
database.update(with: parsedItems, webFeedID: webFeedID, deleteOlder: deleteOlder) { updateArticlesResult in
|
||||||
switch updateArticlesResult {
|
switch updateArticlesResult {
|
||||||
case .success(let articleChanges):
|
case .success(let articleChanges):
|
||||||
self.sendNotificationAbout(articleChanges)
|
self.sendNotificationAbout(articleChanges)
|
||||||
|
@ -136,7 +136,7 @@ private extension CloudKitArticlesZoneDelegate {
|
|||||||
let webFeedIDsAndItems = Dictionary(grouping: parsedItems, by: { item in item.feedURL } ).mapValues { Set($0) }
|
let webFeedIDsAndItems = Dictionary(grouping: parsedItems, by: { item in item.feedURL } ).mapValues { Set($0) }
|
||||||
for (webFeedID, parsedItems) in webFeedIDsAndItems {
|
for (webFeedID, parsedItems) in webFeedIDsAndItems {
|
||||||
group.enter()
|
group.enter()
|
||||||
self.account?.update(webFeedID, with: parsedItems) { result in
|
self.account?.update(webFeedID, with: parsedItems, deleteOlder: false) { result in
|
||||||
switch result {
|
switch result {
|
||||||
case .success(let articleChanges):
|
case .success(let articleChanges):
|
||||||
guard let deletes = articleChanges.deletedArticles, !deletes.isEmpty else {
|
guard let deletes = articleChanges.deletedArticles, !deletes.isEmpty else {
|
||||||
|
@ -204,9 +204,9 @@ public final class ArticlesDatabase {
|
|||||||
// MARK: - Saving, Updating, and Deleting Articles
|
// MARK: - Saving, Updating, and Deleting Articles
|
||||||
|
|
||||||
/// Update articles and save new ones — for feed-based systems (local and iCloud).
|
/// Update articles and save new ones — for feed-based systems (local and iCloud).
|
||||||
public func update(with parsedItems: Set<ParsedItem>, webFeedID: String, completion: @escaping UpdateArticlesCompletionBlock) {
|
public func update(with parsedItems: Set<ParsedItem>, webFeedID: String, deleteOlder: Bool, completion: @escaping UpdateArticlesCompletionBlock) {
|
||||||
precondition(retentionStyle == .feedBased)
|
precondition(retentionStyle == .feedBased)
|
||||||
articlesTable.update(parsedItems, webFeedID, completion)
|
articlesTable.update(parsedItems, webFeedID, deleteOlder, completion)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update articles and save new ones — for sync systems (Feedbin, Feedly, etc.).
|
/// Update articles and save new ones — for sync systems (Feedbin, Feedly, etc.).
|
||||||
|
@ -172,7 +172,7 @@ final class ArticlesTable: DatabaseTable {
|
|||||||
|
|
||||||
// MARK: - Updating and Deleting
|
// MARK: - Updating and Deleting
|
||||||
|
|
||||||
func update(_ parsedItems: Set<ParsedItem>, _ webFeedID: String, _ completion: @escaping UpdateArticlesCompletionBlock) {
|
func update(_ parsedItems: Set<ParsedItem>, _ webFeedID: String, _ deleteOlder: Bool, _ completion: @escaping UpdateArticlesCompletionBlock) {
|
||||||
precondition(retentionStyle == .feedBased)
|
precondition(retentionStyle == .feedBased)
|
||||||
if parsedItems.isEmpty {
|
if parsedItems.isEmpty {
|
||||||
callUpdateArticlesCompletionBlock(nil, nil, nil, completion)
|
callUpdateArticlesCompletionBlock(nil, nil, nil, completion)
|
||||||
@ -210,9 +210,14 @@ final class ArticlesTable: DatabaseTable {
|
|||||||
let updatedArticles = self.findAndSaveUpdatedArticles(incomingArticles, fetchedArticlesDictionary, database) //6
|
let updatedArticles = self.findAndSaveUpdatedArticles(incomingArticles, fetchedArticlesDictionary, database) //6
|
||||||
|
|
||||||
// Articles to delete are 1) not starred and 2) older than 30 days and 3) no longer in feed.
|
// Articles to delete are 1) not starred and 2) older than 30 days and 3) no longer in feed.
|
||||||
let cutoffDate = Date().bySubtracting(days: 30)
|
let articlesToDelete: Set<Article>
|
||||||
let articlesToDelete = fetchedArticles.filter { (article) -> Bool in
|
if deleteOlder {
|
||||||
return !article.status.starred && article.status.dateArrived < cutoffDate && !articleIDs.contains(article.articleID)
|
let cutoffDate = Date().bySubtracting(days: 30)
|
||||||
|
articlesToDelete = fetchedArticles.filter { (article) -> Bool in
|
||||||
|
return !article.status.starred && article.status.dateArrived < cutoffDate && !articleIDs.contains(article.articleID)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
articlesToDelete = Set<Article>()
|
||||||
}
|
}
|
||||||
|
|
||||||
self.callUpdateArticlesCompletionBlock(newArticles, updatedArticles, articlesToDelete, completion) //7
|
self.callUpdateArticlesCompletionBlock(newArticles, updatedArticles, articlesToDelete, completion) //7
|
||||||
|
Loading…
x
Reference in New Issue
Block a user