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; NSMutableArray * recentlyReadStories;
NSMutableSet * recentlyReadFeeds; NSMutableSet * recentlyReadFeeds;
NSMutableArray * readStories; NSMutableArray * readStories;
NSMutableDictionary *folderCountCache;
NSDictionary * dictFolders; NSDictionary * dictFolders;
NSMutableDictionary * dictFeeds; NSMutableDictionary * dictFeeds;
@ -181,6 +182,7 @@
@property (readwrite) NSMutableArray * recentlyReadStories; @property (readwrite) NSMutableArray * recentlyReadStories;
@property (readwrite) NSMutableSet * recentlyReadFeeds; @property (readwrite) NSMutableSet * recentlyReadFeeds;
@property (readwrite) NSMutableArray * readStories; @property (readwrite) NSMutableArray * readStories;
@property (nonatomic) NSMutableDictionary *folderCountCache;
@property (nonatomic) NSDictionary *dictFolders; @property (nonatomic) NSDictionary *dictFolders;
@property (nonatomic, strong) NSMutableDictionary *dictFeeds; @property (nonatomic, strong) NSMutableDictionary *dictFeeds;

View file

@ -103,6 +103,7 @@
@synthesize recentlyReadStories; @synthesize recentlyReadStories;
@synthesize recentlyReadFeeds; @synthesize recentlyReadFeeds;
@synthesize readStories; @synthesize readStories;
@synthesize folderCountCache;
@synthesize dictFolders; @synthesize dictFolders;
@synthesize dictFeeds; @synthesize dictFeeds;
@ -823,6 +824,13 @@
UnreadCounts *counts = [UnreadCounts alloc]; UnreadCounts *counts = [UnreadCounts alloc];
NSArray *folder; 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" || if (folderName == @"river_blurblogs" ||
(!folderName && self.activeFolder == @"river_blurblogs")) { (!folderName && self.activeFolder == @"river_blurblogs")) {
for (id feedId in self.dictSocialFeeds) { 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; return counts;
} }

View file

@ -93,7 +93,6 @@ static const CGFloat kFolderTitleHeight = 28;
[self.intelligenceControl setWidth:62 forSegmentAtIndex:2]; [self.intelligenceControl setWidth:62 forSegmentAtIndex:2];
self.intelligenceControl.hidden = YES; self.intelligenceControl.hidden = YES;
} }
- (void)viewWillAppear:(BOOL)animated { - (void)viewWillAppear:(BOOL)animated {
@ -797,6 +796,7 @@ static const CGFloat kFolderTitleHeight = 28;
appDelegate.readStories = [NSMutableArray array]; appDelegate.readStories = [NSMutableArray array];
appDelegate.isRiverView = NO; appDelegate.isRiverView = NO;
appDelegate.isSocialRiverView = NO; appDelegate.isSocialRiverView = NO;
[appDelegate.folderCountCache removeObjectForKey:folderName];
[appDelegate loadFeedDetailView]; [appDelegate loadFeedDetailView];
} }
@ -932,6 +932,8 @@ static const CGFloat kFolderTitleHeight = 28;
} }
appDelegate.activeFolderFeeds = feeds; appDelegate.activeFolderFeeds = feeds;
[appDelegate.folderCountCache removeObjectForKey:appDelegate.activeFolder];
[appDelegate loadRiverFeedDetailView]; [appDelegate loadRiverFeedDetailView];
} }
@ -1366,6 +1368,8 @@ static const CGFloat kFolderTitleHeight = 28;
appDelegate.dictSocialFeeds = updatedDictSocialFeeds; appDelegate.dictSocialFeeds = updatedDictSocialFeeds;
appDelegate.dictFeeds = updatedDictFeeds; appDelegate.dictFeeds = updatedDictFeeds;
[appDelegate.folderCountCache removeAllObjects];
[self.feedTitlesTable reloadData]; [self.feedTitlesTable reloadData];
} }

View file

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

View file

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