Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve folder's cache error handling #1752

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 31 additions & 24 deletions Vienna/Sources/Models/Folder.m
Original file line number Diff line number Diff line change
Expand Up @@ -687,13 +687,13 @@ -(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];
}
@synchronized(self) {
if (self.isCached && self.containsBodies) {
self.cachedArticles.evictsObjectsWithDiscardedContent = NO;
// attempt to retrieve from cache
NSMutableArray * articles = [NSMutableArray arrayWithCapacity:self.cachedGuids.count];
for (id object in self.cachedGuids) {
Article * theArticle = [self.cachedArticles objectForKey:object];
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;
return [self getCompleteArticles];
}
}
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 getCompleteArticles];
}
} // synchronized
} else {
return [[Database sharedManager] arrayOfArticles:self.itemId filterString:filterString];
}
}

/* getCompleteArticles
* get complete information for all articles
* and store it in cache if appropriate
* returns articles
*/
-(NSArray<Article *> *)getCompleteArticles
{
NSArray * articles = [[Database sharedManager] arrayOfArticles:self.itemId filterString:@""];
self.isCached = NO;
self.containsBodies = NO;
// 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
Loading