From f7ac91922b11642ebb6fc44caf052f465588cba9 Mon Sep 17 00:00:00 2001 From: Tassilo Karge Date: Sun, 20 Oct 2024 19:07:45 +0200 Subject: [PATCH] filter article from cache when it was marked deleted fixes #1834, #1833 In cb9e3b5, a line from Database.m removing the article from cache explicitly was deleted. That led to articles reappearing until the folder cache was purged. --- Vienna/Sources/Database/Database.m | 5 ++++- Vienna/Sources/Models/Folder.m | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Vienna/Sources/Database/Database.m b/Vienna/Sources/Database/Database.m index 19fe00a69b..aaddddca1b 100644 --- a/Vienna/Sources/Database/Database.m +++ b/Vienna/Sources/Database/Database.m @@ -2472,7 +2472,7 @@ -(void)markArticleDeleted:(Article *)article isDeleted:(BOOL)isDeleted NSString * guid = article.guid; Folder * folder = [self folderFromID:folderId]; if (folder !=nil) { - if (isDeleted && !article.read) { + if (isDeleted && !article.read) { [self markArticleRead:folderId guid:guid isRead:YES]; } FMDatabaseQueue *queue = self.databaseQueue; @@ -2483,6 +2483,9 @@ -(void)markArticleDeleted:(Article *)article isDeleted:(BOOL)isDeleted guid]; }]; [article markDeleted:isDeleted]; + //TODO this should all move to the folder implementation, to make this less of a god object. + // Or even better: when marking an article as deleted it triggers the deletion from its folder itself, and that in turn triggers the db update. + // The same also applies to deleteArticle and probably many other parts of this class. if (folder.countOfCachedArticles > 0) { // If we're in a smart folder, the cached article may be different. Article * cachedArticle = [folder articleFromGuid:guid]; diff --git a/Vienna/Sources/Models/Folder.m b/Vienna/Sources/Models/Folder.m index 2ad6b8ad50..fd933995cc 100644 --- a/Vienna/Sources/Models/Folder.m +++ b/Vienna/Sources/Models/Folder.m @@ -739,7 +739,10 @@ -(void)resetArticleStatuses for (id object in self.cachedGuids) { Article * theArticle = [self.cachedArticles objectForKey:object]; if (theArticle != nil) { - [articles addObject:theArticle]; + // deleted articles are not removed from cache any more + if (!theArticle.isDeleted) { + [articles addObject:theArticle]; + } } else { // some problem NSLog(@"Bug retrieving from cache in folder %li : after %lu insertions of %lu, guid %@",(long)self.itemId, (unsigned long)articles.count,(unsigned long)self.cachedGuids.count,object);