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

Use a NSCache for storing folder's articles #508

Merged
merged 10 commits into from Sep 13, 2015
1 change: 0 additions & 1 deletion src/ArticleController.h
Expand Up @@ -76,7 +76,6 @@
-(void)ensureSelectedArticle:(BOOL)singleSelection;
-(void)sortByIdentifier:(NSString *)columnName;
-(void)sortAscending:(BOOL)newAscending;
-(BOOL)currentCacheContainsFolder:(int)folderId;
-(void)deleteArticlesByArray:(NSArray *)articleArray;
-(void)markReadByArray:(NSArray *)articleArray readFlag:(BOOL)readFlag;
-(void)markAllReadByReferencesArray:(NSArray *)refArray readFlag:(BOOL)readFlag;
Expand Down
26 changes: 2 additions & 24 deletions src/ArticleController.m
Expand Up @@ -314,7 +314,6 @@ -(void)displayFolder:(int)newFolderId
{
if (currentFolderId != newFolderId && newFolderId != 0)
{
[[[Database sharedManager] folderFromID:currentFolderId] clearCache];
currentFolderId = newFolderId;
[self reloadArrayOfArticles];
[self sortArticles];
Expand Down Expand Up @@ -374,8 +373,6 @@ -(NSArray *)applyFilter:(NSArray *)unfilteredArray
Folder * folder = [[Database sharedManager] folderFromID:folderIdOfArticleToPreserve];
if (folder != nil)
{
[folder clearCache];
[folder articles];
articleToAdd = [folder articleFromGuid:guidOfArticleToPreserve];
}
if (articleToAdd == nil)
Expand Down Expand Up @@ -703,7 +700,7 @@ -(NSArray *)wrappedMarkAllReadInArray:(NSArray *)folderArray withUndo:(BOOL)undo
else if (IsRSSFolder(folder))
{
if (undoFlag) {
[refArray addObjectsFromArray:[[Database sharedManager] arrayOfUnreadArticlesRefs:folderId]];
[refArray addObjectsFromArray:[folder arrayOfUnreadArticlesRefs]];
}
if ([[Database sharedManager] markFolderRead:folderId])
{
Expand All @@ -713,7 +710,7 @@ -(NSArray *)wrappedMarkAllReadInArray:(NSArray *)folderArray withUndo:(BOOL)undo
}
else if (IsGoogleReaderFolder(folder))
{
NSArray * articleArray = [[Database sharedManager] arrayOfUnreadArticlesRefs:folderId];
NSArray * articleArray = [folder arrayOfUnreadArticlesRefs];
if (undoFlag) {
[refArray addObjectsFromArray:articleArray];
}
Expand All @@ -733,25 +730,6 @@ -(NSArray *)wrappedMarkAllReadInArray:(NSArray *)folderArray withUndo:(BOOL)undo
return refArray;
}

/* currentCacheContainsFolder
* Scans the current article cache to determine if any article is a member of the specified
* folder and returns YES if so.
*/
-(BOOL)currentCacheContainsFolder:(int)folderId
{
int count = [currentArrayOfArticles count];
int index = 0;

while (index < count)
{
Article * anArticle = [currentArrayOfArticles objectAtIndex:index];
if ([anArticle folderId] == folderId)
return YES;
++index;
}
return NO;
}

/* markAllReadByReferencesArray
* Given an array of references, mark all those articles read or unread.
*/
Expand Down
4 changes: 3 additions & 1 deletion src/Database.h
Expand Up @@ -88,6 +88,7 @@
-(BOOL)setParent:(NSInteger)newParentID forFolder:(NSInteger)folderId;
-(BOOL)setFirstChild:(NSInteger)childId forFolder:(NSInteger)folderId;
-(BOOL)setNextSibling:(NSUInteger)nextSiblingId forFolder:(NSInteger)folderId;
-(void)prepareCache:(NSCache *)cache forFolder:(NSInteger)folderId saveGuidsIn:(NSMutableArray *)cachedGuids;
-(void)handleAutoSortFoldersTreeChange:(NSNotification *)notification;

// RSS folder functions
Expand All @@ -108,7 +109,8 @@
-(NSString *)criteriaToSQL:(CriteriaTree *)criteriaTree;

// Article functions
-(BOOL)createArticle:(NSInteger)folderID article:(Article *)article guidHistory:(NSArray *)guidHistory;
-(BOOL)addArticle:(Article *)article toFolder:(NSInteger)folderID;
-(BOOL)updateArticle:(Article *)existingArticle ofFolder:(NSInteger)folderID withArticle:(Article *)article;
-(BOOL)deleteArticleFromFolder:(NSInteger)folderId guid:(NSString *)guid;
-(NSArray *)arrayOfUnreadArticlesRefs:(NSInteger)folderId;
-(NSArray *)arrayOfArticles:(NSInteger)folderId filterString:(NSString *)filterString;
Expand Down