From 5e34e27ee68b2562921564b4a4bac64ec2cedc37 Mon Sep 17 00:00:00 2001 From: Barijaona Ramaholimihaso Date: Fri, 13 Sep 2024 14:01:55 +0300 Subject: [PATCH] Speed up the emptying of articles' statuses Apply process optimization similar to the one used for marking all articles of a feed read. --- Vienna/Sources/Models/Folder.m | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Vienna/Sources/Models/Folder.m b/Vienna/Sources/Models/Folder.m index be3accf63c..ebcad438f8 100644 --- a/Vienna/Sources/Models/Folder.m +++ b/Vienna/Sources/Models/Folder.m @@ -46,6 +46,7 @@ @interface Folder () @implementation Folder { NSInteger unreadCount; NSInteger childUnreadCount; + NSInteger latestFetchCount; // count of new/updated articles fetched during a feed refresh VNAFolderFlag nonPersistedFlags; VNAFolderFlag flags; } @@ -508,6 +509,7 @@ -(BOOL)createArticle:(Article *)article guidHistory:(NSArray *)guidHistory if (success) { [article beginContentAccess]; article.status = ArticleStatusNew; + latestFetchCount++; // add to the cache NSString * guid = article.guid; [self.cachedArticles setObject:article forKey:guid]; @@ -535,6 +537,7 @@ -(BOOL)createArticle:(Article *)article guidHistory:(NSArray *)guidHistory } else { article.status = ArticleStatusUpdated; } + latestFetchCount++; } else { return NO; } @@ -663,14 +666,25 @@ -(void)markArticlesInCacheRead */ -(void)resetArticleStatuses { - for (NSString * guid in self.cachedGuids) { + NSInteger count = latestFetchCount; + // we take profit from the fact that the articles + // which were fetched during the last feed refresh + // are located at the end of the array + for (NSString * guid in self.cachedGuids.reverseObjectEnumerator.allObjects) { Article * article = [self.cachedArticles objectForKey:guid]; - if (article) { + if (article && + (article.status == ArticleStatusNew || article.status == ArticleStatusUpdated)) + { [article beginContentAccess]; article.status = ArticleStatusEmpty; [article endContentAccess]; + count--; + if (count == 0) { + break; + } } } + latestFetchCount = 0; } /* arrayOfUnreadArticlesRefs