Skip to content

Commit

Permalink
Improve folder's cache error handling
Browse files Browse the repository at this point in the history
Fix articles not being displayed when, for some reason, error messages
"Bug retrieving for cache in folder …" appear in logs.
  • Loading branch information
barijaona committed Jun 17, 2024
1 parent 284f58a commit 90da870
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions Vienna/Sources/Models/Folder.m
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ -(NSArray *)arrayOfUnreadArticlesRefs
NSMutableArray * articles = [NSMutableArray array];
NSArray * subFolders = [[Database sharedManager] arrayOfFolders:self.itemId];
for (Folder * folder in subFolders) {
[articles addObjectsFromArray:[folder articlesWithFilter:filterString]];
[articles addObjectsFromArray:[folder articlesWithFilter:@""]];
}
return [articles copy];
}
Expand All @@ -702,38 +702,45 @@ -(NSArray *)arrayOfUnreadArticlesRefs
} 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);
self.isCached = NO;
self.containsBodies = NO;
break;
self.cachedArticles.evictsObjectsWithDiscardedContent = YES;
return [self getArticlesAndCache];
}
}
self.cachedArticles.evictsObjectsWithDiscardedContent = YES;
return [articles copy];
} else {
NSArray * articles = [[Database sharedManager] arrayOfArticles:self.itemId filterString:filterString];
// Only feeds folders can be cached, as they are the only ones to guarantee
// bijection : one article <-> one guid
if (self.type == VNAFolderTypeRSS || self.type == VNAFolderTypeOpenReader) {
self.isCached = NO;
self.containsBodies = NO;
[self.cachedArticles removeAllObjects];
[self.cachedGuids removeAllObjects];
for (id object in articles) {
NSString * guid = ((Article *)object).guid;
[self.cachedArticles setObject:object forKey:[NSString stringWithString:guid]];
[self.cachedGuids addObject:guid];
}
self.isCached = YES;
self.containsBodies = YES;
}
return articles;
}
return [self getArticlesAndCache];
}
} // synchronized
} else {
return [[Database sharedManager] arrayOfArticles:self.itemId filterString:filterString];
}
}

/* getArticlesAndCache
* Returns articles and store in cache if possible
*/
-(NSArray<Article *> *)getArticlesAndCache
{
self.isCached = NO;
self.containsBodies = NO;
NSArray * articles = [[Database sharedManager] arrayOfArticles:self.itemId filterString:@""];
// Only feeds folders can be cached, as they are the only ones to guarantee
// bijection : one article <-> one guid
if (self.type == VNAFolderTypeRSS || self.type == VNAFolderTypeOpenReader) {
[self.cachedArticles removeAllObjects];
[self.cachedGuids removeAllObjects];
for (id object in articles) {
NSString * guid = ((Article *)object).guid;
[self.cachedArticles setObject:object forKey:[NSString stringWithString:guid]];
[self.cachedGuids addObject:guid];
}
self.isCached = YES;
self.containsBodies = YES;
}
return articles;
}

/* folderNameCompare
* Returns the result of comparing two folders by folder name.
*/
Expand Down

0 comments on commit 90da870

Please sign in to comment.