Caching unread counts for folders so scrolling is super-fast again in ios feed list.

This commit is contained in:
Samuel Clay 2012-10-14 17:30:03 -07:00
parent acfc6abce0
commit 9db137dee9
5 changed files with 29 additions and 14 deletions

View file

@ -105,6 +105,7 @@
NSMutableArray * recentlyReadStories;
NSMutableSet * recentlyReadFeeds;
NSMutableArray * readStories;
NSMutableDictionary *folderCountCache;
NSDictionary * dictFolders;
NSMutableDictionary * dictFeeds;
@ -181,6 +182,7 @@
@property (readwrite) NSMutableArray * recentlyReadStories;
@property (readwrite) NSMutableSet * recentlyReadFeeds;
@property (readwrite) NSMutableArray * readStories;
@property (nonatomic) NSMutableDictionary *folderCountCache;
@property (nonatomic) NSDictionary *dictFolders;
@property (nonatomic, strong) NSMutableDictionary *dictFeeds;

View file

@ -103,6 +103,7 @@
@synthesize recentlyReadStories;
@synthesize recentlyReadFeeds;
@synthesize readStories;
@synthesize folderCountCache;
@synthesize dictFolders;
@synthesize dictFeeds;
@ -823,6 +824,13 @@
UnreadCounts *counts = [UnreadCounts alloc];
NSArray *folder;
if ([[self.folderCountCache objectForKey:folderName] boolValue]) {
counts.ps = [[self.folderCountCache objectForKey:[NSString stringWithFormat:@"%@-ps", folderName]] intValue];
counts.nt = [[self.folderCountCache objectForKey:[NSString stringWithFormat:@"%@-nt", folderName]] intValue];
counts.ng = [[self.folderCountCache objectForKey:[NSString stringWithFormat:@"%@-ng", folderName]] intValue];
return counts;
}
if (folderName == @"river_blurblogs" ||
(!folderName && self.activeFolder == @"river_blurblogs")) {
for (id feedId in self.dictSocialFeeds) {
@ -845,6 +853,14 @@
}
}
if (!self.folderCountCache) {
self.folderCountCache = [[NSMutableDictionary alloc] init];
}
[self.folderCountCache setObject:[NSNumber numberWithBool:YES] forKey:folderName];
[self.folderCountCache setObject:[NSNumber numberWithInt:counts.ps] forKey:[NSString stringWithFormat:@"%@-ps", folderName]];
[self.folderCountCache setObject:[NSNumber numberWithInt:counts.nt] forKey:[NSString stringWithFormat:@"%@-nt", folderName]];
[self.folderCountCache setObject:[NSNumber numberWithInt:counts.ng] forKey:[NSString stringWithFormat:@"%@-ng", folderName]];
return counts;
}

View file

@ -92,7 +92,6 @@ static const CGFloat kFolderTitleHeight = 28;
[self.intelligenceControl setWidth:68 forSegmentAtIndex:1];
[self.intelligenceControl setWidth:62 forSegmentAtIndex:2];
self.intelligenceControl.hidden = YES;
}
@ -797,7 +796,8 @@ static const CGFloat kFolderTitleHeight = 28;
appDelegate.readStories = [NSMutableArray array];
appDelegate.isRiverView = NO;
appDelegate.isSocialRiverView = NO;
[appDelegate.folderCountCache removeObjectForKey:folderName];
[appDelegate loadFeedDetailView];
}
@ -931,7 +931,9 @@ static const CGFloat kFolderTitleHeight = 28;
}
appDelegate.activeFolderFeeds = feeds;
[appDelegate.folderCountCache removeObjectForKey:appDelegate.activeFolder];
[appDelegate loadRiverFeedDetailView];
}
@ -1366,6 +1368,8 @@ static const CGFloat kFolderTitleHeight = 28;
appDelegate.dictSocialFeeds = updatedDictSocialFeeds;
appDelegate.dictFeeds = updatedDictFeeds;
[appDelegate.folderCountCache removeAllObjects];
[self.feedTitlesTable reloadData];
}

View file

@ -317,7 +317,6 @@
// } else if ([[appDelegate.activeStory objectForKey:@"reply_count"] intValue] == 1) {
// replyStr = [NSString stringWithFormat:@" and <b>%@ replies</b>", [appDelegate.activeStory objectForKey:@"reply_count"]];
// }
NSLog(@"[appDelegate.activeStory objectForKey:@'comment_count'] %@", [[appDelegate.activeStory objectForKey:@"comment_count"] class]);
if (![[appDelegate.activeStory objectForKey:@"comment_count"] isKindOfClass:[NSNull class]] &&
[[appDelegate.activeStory objectForKey:@"comment_count"] intValue]) {
commentLabel = [commentLabel stringByAppendingString:[NSString stringWithFormat:@
@ -336,7 +335,6 @@
//replyStr,
[self getAvatars:@"commented_by_friends"],
[self getAvatars:@"commented_by_public"]]];
NSLog(@"commentLabel is %@", commentLabel);
}
if (![[appDelegate.activeStory objectForKey:@"share_count"] isKindOfClass:[NSNull class]] &&
@ -357,7 +355,6 @@
[[appDelegate.activeStory objectForKey:@"share_count"] intValue] == 1
? [NSString stringWithFormat:@"<b>1 share</b>"] :
[NSString stringWithFormat:@"<b>%@ shares</b>", [appDelegate.activeStory objectForKey:@"share_count"]]]];
NSLog(@"commentLabel is %@", commentLabel);
}
if ([appDelegate.activeStory objectForKey:@"share_count"] != [NSNull null] &&
@ -637,7 +634,6 @@
- (void)showStory {
appDelegate.inStoryDetail = YES;
NSLog(@"in showStory");
// when we show story, we mark it as read
[self markStoryAsRead];
self.noStorySelectedLabel.hidden = YES;
@ -776,7 +772,7 @@
footerString
];
NSLog(@"\n\n\n\nhtmlString:\n\n\n%@\n\n\n", htmlString);
// NSLog(@"\n\n\n\nhtmlString:\n\n\n%@\n\n\n", htmlString);
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
@ -1168,7 +1164,6 @@ shouldStartLoadWithRequest:(NSURLRequest *)request
if (appDelegate.isSocialRiverView) {
// grab the user id from the shared_by_friends
NSArray *storyId = [NSArray arrayWithObject:[appDelegate.activeStory objectForKey:@"id"]];
NSLog(@"[appDelegate.activeStory objectForKey:@shared_by_friends] %@", [appDelegate.activeStory objectForKey:@"shared_by_friends"]);
NSString *friendUserId;
if ([[appDelegate.activeStory objectForKey:@"shared_by_friends"] count]) {
@ -1433,8 +1428,6 @@ shouldStartLoadWithRequest:(NSURLRequest *)request
int nextIndex = [appDelegate indexOfNextStory];
NSLog(@"nextIndex is %i", nextIndex);
[self.loadingIndicator stopAnimating];
if (self.appDelegate.feedDetailViewController.pageFetching) {

View file

@ -8,11 +8,11 @@
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Classes/NewsBlurViewController.m"
timestampString = "371836607.254596"
timestampString = "371953230.901928"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "601"
endingLineNumber = "601"
startingLineNumber = "600"
endingLineNumber = "600"
landmarkName = "-switchSitesUnread"
landmarkType = "5">
</FileBreakpoint>