From 9db137dee9ab190b7661818c07249a31371e7c64 Mon Sep 17 00:00:00 2001 From: Samuel Clay Date: Sun, 14 Oct 2012 17:30:03 -0700 Subject: [PATCH] Caching unread counts for folders so scrolling is super-fast again in ios feed list. --- media/ios/Classes/NewsBlurAppDelegate.h | 2 ++ media/ios/Classes/NewsBlurAppDelegate.m | 16 ++++++++++++++++ media/ios/Classes/NewsBlurViewController.m | 10 +++++++--- media/ios/Classes/StoryDetailViewController.m | 9 +-------- .../xcdebugger/Breakpoints.xcbkptlist | 6 +++--- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/media/ios/Classes/NewsBlurAppDelegate.h b/media/ios/Classes/NewsBlurAppDelegate.h index 0d04d67a4..4a30173aa 100644 --- a/media/ios/Classes/NewsBlurAppDelegate.h +++ b/media/ios/Classes/NewsBlurAppDelegate.h @@ -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; diff --git a/media/ios/Classes/NewsBlurAppDelegate.m b/media/ios/Classes/NewsBlurAppDelegate.m index bb5f46a02..798f0bb21 100644 --- a/media/ios/Classes/NewsBlurAppDelegate.m +++ b/media/ios/Classes/NewsBlurAppDelegate.m @@ -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; } diff --git a/media/ios/Classes/NewsBlurViewController.m b/media/ios/Classes/NewsBlurViewController.m index 6554f604b..0516e9329 100644 --- a/media/ios/Classes/NewsBlurViewController.m +++ b/media/ios/Classes/NewsBlurViewController.m @@ -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]; } diff --git a/media/ios/Classes/StoryDetailViewController.m b/media/ios/Classes/StoryDetailViewController.m index fcd30c521..48b8d0bc1 100644 --- a/media/ios/Classes/StoryDetailViewController.m +++ b/media/ios/Classes/StoryDetailViewController.m @@ -317,7 +317,6 @@ // } else if ([[appDelegate.activeStory objectForKey:@"reply_count"] intValue] == 1) { // replyStr = [NSString stringWithFormat:@" and %@ replies", [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:@"1 share"] : [NSString stringWithFormat:@"%@ shares", [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) { diff --git a/media/ios/NewsBlur.xcodeproj/xcuserdata/sclay.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist b/media/ios/NewsBlur.xcodeproj/xcuserdata/sclay.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist index a4635e3c7..f04d84439 100644 --- a/media/ios/NewsBlur.xcodeproj/xcuserdata/sclay.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist +++ b/media/ios/NewsBlur.xcodeproj/xcuserdata/sclay.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist @@ -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">