Skip to content

Commit

Permalink
Speed up the emptying of articles' statuses
Browse files Browse the repository at this point in the history
Apply process optimization similar to the one used for marking all
articles of a feed read.
  • Loading branch information
barijaona committed Sep 13, 2024
1 parent e16edf1 commit 5e34e27
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions Vienna/Sources/Models/Folder.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -535,6 +537,7 @@ -(BOOL)createArticle:(Article *)article guidHistory:(NSArray *)guidHistory
} else {
article.status = ArticleStatusUpdated;
}
latestFetchCount++;
} else {
return NO;
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5e34e27

Please sign in to comment.