Bgerstle has submitted this change and it was merged. Change subject: Fix for article not reloading from cache on app start. ......................................................................
Fix for article not reloading from cache on app start. Also fixed issue with both article Images.plist and section Images.plist being doubled in size every time an article was refreshed. Bug: T101078 Change-Id: I8d461cb09c6b6a7381ba5ee01fc9cadcd6f49c17 --- M MediaWikiKit/MediaWikiKit/MWKHistoryEntry.h M MediaWikiKit/MediaWikiKit/MWKImageList.h M MediaWikiKit/MediaWikiKit/MWKImageList.m M Wikipedia.xcodeproj/project.pbxproj M Wikipedia/C Methods/WMFArticleParsing.m A Wikipedia/Categories/NSURL+Extras.h A Wikipedia/Categories/NSURL+Extras.m M Wikipedia/Networking/Fetchers/ArticleFetcher.m M Wikipedia/View Controllers/Preview/PreviewAndSaveViewController.m M Wikipedia/View Controllers/WebView/WebViewController.h M Wikipedia/View Controllers/WebView/WebViewController.m M WikipediaUnitTests/ArticleLoadingTests.m 12 files changed, 82 insertions(+), 28 deletions(-) Approvals: Fjalapeno: Looks good to me, but someone else must approve Bgerstle: Looks good to me, approved jenkins-bot: Verified diff --git a/MediaWikiKit/MediaWikiKit/MWKHistoryEntry.h b/MediaWikiKit/MediaWikiKit/MWKHistoryEntry.h index 2993426..a669565 100644 --- a/MediaWikiKit/MediaWikiKit/MWKHistoryEntry.h +++ b/MediaWikiKit/MediaWikiKit/MWKHistoryEntry.h @@ -16,7 +16,8 @@ MWKHistoryDiscoveryMethodLink, MWKHistoryDiscoveryMethodBackForward, MWKHistoryDiscoveryMethodSaved, - MWKHistoryDiscoveryMethodReload, + MWKHistoryDiscoveryMethodReloadFromNetwork, + MWKHistoryDiscoveryMethodReloadFromCache, MWKHistoryDiscoveryMethodUnknown }; diff --git a/MediaWikiKit/MediaWikiKit/MWKImageList.h b/MediaWikiKit/MediaWikiKit/MWKImageList.h index 9620ded..28aa906 100644 --- a/MediaWikiKit/MediaWikiKit/MWKImageList.h +++ b/MediaWikiKit/MediaWikiKit/MWKImageList.h @@ -26,7 +26,7 @@ - (void)addImageURL:(NSString*)imageURL; -- (BOOL)hasImageURL:(NSString*)imageURL; +- (BOOL)hasImageURL:(NSURL*)imageURL; - (MWKImage*)imageWithURL:(NSString*)imageURL; diff --git a/MediaWikiKit/MediaWikiKit/MWKImageList.m b/MediaWikiKit/MediaWikiKit/MWKImageList.m index 63d5208..56ad161 100644 --- a/MediaWikiKit/MediaWikiKit/MWKImageList.m +++ b/MediaWikiKit/MediaWikiKit/MWKImageList.m @@ -8,6 +8,7 @@ #import "MediaWikiKit.h" #import "NSString+Extras.h" +#import "NSURL+Extras.h" @interface MWKImageList () @@ -87,8 +88,13 @@ return [self.article.dataStore imageWithURL:imageURL article:self.article]; } -- (BOOL)hasImageURL:(NSString*)imageURL { - return [self imageWithURL:imageURL] != nil; +- (BOOL)hasImageURL:(NSURL*)imageURL { + NSString* imageURLString = [imageURL wmf_schemelessURLString]; + if (imageURLString && imageURLString.length > 0 && [self.entries containsObject:imageURLString]) { + return YES; + } else { + return NO; + } } - (MWKImage*)imageWithURL:(NSString*)imageURL { @@ -185,6 +191,7 @@ } - (BOOL)addImageURLIfAbsent:(NSString*)imageURL { + imageURL = [imageURL wmf_schemelessURL]; if (imageURL && imageURL.length > 0 && ![self.entries containsObject:imageURL]) { [self addImageURL:imageURL]; return YES; diff --git a/Wikipedia.xcodeproj/project.pbxproj b/Wikipedia.xcodeproj/project.pbxproj index af6fb6a..52f1d6e 100644 --- a/Wikipedia.xcodeproj/project.pbxproj +++ b/Wikipedia.xcodeproj/project.pbxproj @@ -69,6 +69,7 @@ 04530AF51935BF4D00022512 /* ModalMenuAndContentViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 04530AF41935BF4D00022512 /* ModalMenuAndContentViewController.m */; }; 04530AF81935C07500022512 /* ModalContentViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 04530AF71935C07500022512 /* ModalContentViewController.m */; }; 04530AFB1935C2B500022512 /* EmptySegue.m in Sources */ = {isa = PBXBuildFile; fileRef = 04530AFA1935C2B500022512 /* EmptySegue.m */; }; + 045AB8C31B1E15D9002839D7 /* NSURL+Extras.m in Sources */ = {isa = PBXBuildFile; fileRef = 045AB8C21B1E15D9002839D7 /* NSURL+Extras.m */; }; 045D872119FAD2FA0035C1F9 /* AboutViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 045D872019FAD2FA0035C1F9 /* AboutViewController.m */; }; 04616DFC1AE706C600815BCE /* WMFLocalizationProtocol.m in Sources */ = {isa = PBXBuildFile; fileRef = 04616DFB1AE706C600815BCE /* WMFLocalizationProtocol.m */; }; 0462A6D11A1FE016009412D4 /* SearchResultAttributedString.m in Sources */ = {isa = PBXBuildFile; fileRef = 0462A6D01A1FE016009412D4 /* SearchResultAttributedString.m */; }; @@ -508,6 +509,8 @@ 04530AF71935C07500022512 /* ModalContentViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ModalContentViewController.m; sourceTree = "<group>"; }; 04530AF91935C2B500022512 /* EmptySegue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EmptySegue.h; sourceTree = "<group>"; }; 04530AFA1935C2B500022512 /* EmptySegue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EmptySegue.m; sourceTree = "<group>"; }; + 045AB8C11B1E15D9002839D7 /* NSURL+Extras.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSURL+Extras.h"; sourceTree = "<group>"; }; + 045AB8C21B1E15D9002839D7 /* NSURL+Extras.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSURL+Extras.m"; sourceTree = "<group>"; }; 045D871F19FAD2FA0035C1F9 /* AboutViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AboutViewController.h; sourceTree = "<group>"; }; 045D872019FAD2FA0035C1F9 /* AboutViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AboutViewController.m; sourceTree = "<group>"; }; 04616DFA1AE706C600815BCE /* WMFLocalizationProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WMFLocalizationProtocol.h; sourceTree = "<group>"; }; @@ -1782,6 +1785,8 @@ 04C43AB9183442FC006C643B /* NSRunLoop+TimeOutAndFlag.m */, 04C43ABA183442FC006C643B /* NSString+Extras.h */, 04C43ABB183442FC006C643B /* NSString+Extras.m */, + 045AB8C11B1E15D9002839D7 /* NSURL+Extras.h */, + 045AB8C21B1E15D9002839D7 /* NSURL+Extras.m */, 04B91AA918E3D9E200FFAA1C /* NSString+FormattedAttributedString.h */, 04B91AAA18E3D9E200FFAA1C /* NSString+FormattedAttributedString.m */, 042487501A54BECD00A5C905 /* MWKArticle+Convenience.h */, @@ -3126,6 +3131,7 @@ BCB58F671A8AA22200465627 /* MWKLicense+ToGlyph.m in Sources */, 04C757671A1A9E1B0084AC39 /* RecentSearchesViewController.m in Sources */, 04C43AAE18344131006C643B /* CommunicationBridge.m in Sources */, + 045AB8C31B1E15D9002839D7 /* NSURL+Extras.m in Sources */, 04224501197F5E09005DD0BF /* BulletedLabel.m in Sources */, C979727D1A731F2D00C6ED7A /* WMFShareOptionsView.m in Sources */, C91A86F41A8BCB680088A801 /* WMFShareCardImageContainer.m in Sources */, diff --git a/Wikipedia/C Methods/WMFArticleParsing.m b/Wikipedia/C Methods/WMFArticleParsing.m index bae2a5a..b97e734 100644 --- a/Wikipedia/C Methods/WMFArticleParsing.m +++ b/Wikipedia/C Methods/WMFArticleParsing.m @@ -97,20 +97,22 @@ } } - MWKImage* image = [article importImageURL:srcTagImageURL sectionId:sectionID]; + if (![article.images hasImageURL:[NSURL URLWithString:srcTagImageURL]]) { + MWKImage* image = [article importImageURL:srcTagImageURL sectionId:sectionID]; - // If img tag dimensions were extracted, save them so they don't have to be expensively determined later. - if (imgWidth && imgHeight) { - // Don't record dimensions if image file name doesn't have size prefix. - // (Sizes from the img tag don't tend to correspond closely to actual - // image binary sizes for these.) - if ([MWKImage fileSizePrefix:srcTagImageURL] != NSNotFound) { - image.width = @(imgWidth.integerValue * density); - image.height = @(imgHeight.integerValue * density); + // If img tag dimensions were extracted, save them so they don't have to be expensively determined later. + if (imgWidth && imgHeight) { + // Don't record dimensions if image file name doesn't have size prefix. + // (Sizes from the img tag don't tend to correspond closely to actual + // image binary sizes for these.) + if ([MWKImage fileSizePrefix:srcTagImageURL] != NSNotFound) { + image.width = @(imgWidth.integerValue * density); + image.height = @(imgHeight.integerValue * density); + } } - } - [image save]; + [image save]; + } } } diff --git a/Wikipedia/Categories/NSURL+Extras.h b/Wikipedia/Categories/NSURL+Extras.h new file mode 100644 index 0000000..c37c3ce --- /dev/null +++ b/Wikipedia/Categories/NSURL+Extras.h @@ -0,0 +1,8 @@ +// Created by Monte Hurd on 6/2/15. +// Copyright (c) 2015 Wikimedia Foundation. Provided under MIT-style license; please copy and modify! + +@interface NSURL (Extras) + +- (NSString*)wmf_schemelessURLString; + +@end diff --git a/Wikipedia/Categories/NSURL+Extras.m b/Wikipedia/Categories/NSURL+Extras.m new file mode 100644 index 0000000..719e33f --- /dev/null +++ b/Wikipedia/Categories/NSURL+Extras.m @@ -0,0 +1,18 @@ +// Created by Monte Hurd on 6/2/15. +// Copyright (c) 2015 Wikimedia Foundation. Provided under MIT-style license; please copy and modify! + +#import "NSURL+Extras.h" + +@implementation NSURL (Extras) + +- (NSString*)wmf_schemelessURLString { + NSRange dividerRange = [self.absoluteString rangeOfString:@"://"]; + if (dividerRange.location == NSNotFound) { + return self.absoluteString; + } + NSUInteger divide = NSMaxRange(dividerRange) - 2; + NSString* path = [self.absoluteString substringFromIndex:divide]; + return path; +} + +@end diff --git a/Wikipedia/Networking/Fetchers/ArticleFetcher.m b/Wikipedia/Networking/Fetchers/ArticleFetcher.m index 320b68a..0a908a5 100644 --- a/Wikipedia/Networking/Fetchers/ArticleFetcher.m +++ b/Wikipedia/Networking/Fetchers/ArticleFetcher.m @@ -229,6 +229,9 @@ self.article.thumbnailURL = thumbURL; } + if ([[self.article existingImageWithURL:thumbURL] isCached]) { + return; + } NSString* cacheFilePath = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject] diff --git a/Wikipedia/View Controllers/Preview/PreviewAndSaveViewController.m b/Wikipedia/View Controllers/Preview/PreviewAndSaveViewController.m index a9c61d7..3bb03cd 100644 --- a/Wikipedia/View Controllers/Preview/PreviewAndSaveViewController.m +++ b/Wikipedia/View Controllers/Preview/PreviewAndSaveViewController.m @@ -506,7 +506,7 @@ [self.funnel logSavedRevision:[fetchedData[@"newrevid"] intValue]]; WebViewController* webVC = [self.navigationController searchNavStackForViewControllerOfClass:[WebViewController class]]; - [webVC reloadCurrentArticle]; + [webVC reloadCurrentArticleFromNetwork]; [ROOT popToViewController:webVC animated:YES]; } break; diff --git a/Wikipedia/View Controllers/WebView/WebViewController.h b/Wikipedia/View Controllers/WebView/WebViewController.h index 6049c91..598ad23 100644 --- a/Wikipedia/View Controllers/WebView/WebViewController.h +++ b/Wikipedia/View Controllers/WebView/WebViewController.h @@ -32,7 +32,7 @@ - (void)referencesShow:(NSDictionary*)payload; - (void)referencesHide; -- (void)reloadCurrentArticle; +- (void)reloadCurrentArticleFromNetwork; - (void)navigateToPage:(MWKTitle*)title discoveryMethod:(MWKHistoryDiscoveryMethod)discoveryMethod; diff --git a/Wikipedia/View Controllers/WebView/WebViewController.m b/Wikipedia/View Controllers/WebView/WebViewController.m index f31777c..7c51a36 100644 --- a/Wikipedia/View Controllers/WebView/WebViewController.m +++ b/Wikipedia/View Controllers/WebView/WebViewController.m @@ -145,7 +145,7 @@ [self tocSetupSwipeGestureRecognizers]; - [self reloadCurrentArticle]; + [self reloadCurrentArticleFromCache]; // Restrict the web view from scrolling horizonally. [self.webView.scrollView addObserver:self @@ -1348,7 +1348,7 @@ self.jumpToFragment = title.fragment; - if (discoveryMethod != MWKHistoryDiscoveryMethodBackForward && discoveryMethod != MWKHistoryDiscoveryMethodReload) { + if (discoveryMethod != MWKHistoryDiscoveryMethodBackForward && discoveryMethod != MWKHistoryDiscoveryMethodReloadFromNetwork && discoveryMethod != MWKHistoryDiscoveryMethodReloadFromCache) { [self updateHistoryDateVisitedForArticleBeingNavigatedFrom]; } @@ -1364,9 +1364,14 @@ */ } -- (void)reloadCurrentArticle { +- (void)reloadCurrentArticleFromNetwork { [self navigateToPage:self.session.currentArticle.title - discoveryMethod:MWKHistoryDiscoveryMethodReload]; + discoveryMethod:MWKHistoryDiscoveryMethodReloadFromNetwork]; +} + +- (void)reloadCurrentArticleFromCache { + [self navigateToPage:self.session.currentArticle.title + discoveryMethod:MWKHistoryDiscoveryMethodReloadFromCache]; } - (void)cancelArticleLoading { @@ -1394,14 +1399,15 @@ case MWKHistoryDiscoveryMethodSearch: case MWKHistoryDiscoveryMethodRandom: case MWKHistoryDiscoveryMethodLink: - case MWKHistoryDiscoveryMethodReload: + case MWKHistoryDiscoveryMethodReloadFromNetwork: case MWKHistoryDiscoveryMethodUnknown: { needsRefresh = YES; break; } case MWKHistoryDiscoveryMethodSaved: - case MWKHistoryDiscoveryMethodBackForward: { + case MWKHistoryDiscoveryMethodBackForward: + case MWKHistoryDiscoveryMethodReloadFromCache: { needsRefresh = NO; break; } @@ -1665,13 +1671,14 @@ case MWKHistoryDiscoveryMethodSearch: case MWKHistoryDiscoveryMethodRandom: case MWKHistoryDiscoveryMethodLink: + case MWKHistoryDiscoveryMethodReloadFromNetwork: case MWKHistoryDiscoveryMethodUnknown: { // Update the history so the most recently viewed article appears at the top. [self.session.userDataStore updateHistory:title discoveryMethod:self.session.currentArticleDiscoveryMethod]; break; } - case MWKHistoryDiscoveryMethodReload: + case MWKHistoryDiscoveryMethodReloadFromCache: case MWKHistoryDiscoveryMethodBackForward: // Traversing history should not alter it, and should be served from the cache. break; @@ -1713,7 +1720,8 @@ if (self.session.currentArticleDiscoveryMethod == MWKHistoryDiscoveryMethodSaved || self.session.currentArticleDiscoveryMethod == MWKHistoryDiscoveryMethodBackForward || - self.session.currentArticleDiscoveryMethod == MWKHistoryDiscoveryMethodReload) { + self.session.currentArticleDiscoveryMethod == MWKHistoryDiscoveryMethodReloadFromNetwork || + self.session.currentArticleDiscoveryMethod == MWKHistoryDiscoveryMethodReloadFromCache) { MWKHistoryEntry* historyEntry = [self.session.userDataStore.historyList entryForTitle:article.title]; CGPoint scrollOffset = CGPointMake(0, historyEntry.scrollPosition); self.lastScrollOffset = scrollOffset; @@ -1882,7 +1890,7 @@ } - (void)refreshWasPulled { - [self reloadCurrentArticle]; + [self reloadCurrentArticleFromNetwork]; } - (BOOL)refreshShouldShow { diff --git a/WikipediaUnitTests/ArticleLoadingTests.m b/WikipediaUnitTests/ArticleLoadingTests.m index d69e863..4924f87 100644 --- a/WikipediaUnitTests/ArticleLoadingTests.m +++ b/WikipediaUnitTests/ArticleLoadingTests.m @@ -45,7 +45,7 @@ // self.session.currentArticle = dummyArticle; // // [self.webVC navigateToPage:dummyArticle.title -// discoveryMethod:MWKHistoryDiscoveryMethodReload]; +// discoveryMethod:MWKHistoryDiscoveryMethodReloadFromNetwork]; // // // TODO: verify that mock article fetcher gets a call to fetch article w/ mock title // @@ -111,7 +111,8 @@ // self.session.currentArticle = originalArticle; // // // should be true for every discovery -// MWKHistoryDiscoveryMethod methods[7] = {MWKHistoryDiscoveryMethodReload, +// MWKHistoryDiscoveryMethod methods[7] = {MWKHistoryDiscoveryMethodReloadFromNetwork, +// MWKHistoryDiscoveryMethodReloadFromCache, // MWKHistoryDiscoveryMethodLink, // MWKHistoryDiscoveryMethodRandom, // MWKHistoryDiscoveryMethodSaved, -- To view, visit https://gerrit.wikimedia.org/r/215277 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I8d461cb09c6b6a7381ba5ee01fc9cadcd6f49c17 Gerrit-PatchSet: 7 Gerrit-Project: apps/ios/wikipedia Gerrit-Branch: master Gerrit-Owner: Mhurd <mh...@wikimedia.org> Gerrit-Reviewer: Bgerstle <bgers...@wikimedia.org> Gerrit-Reviewer: Fjalapeno <cfl...@wikimedia.org> Gerrit-Reviewer: Mhurd <mh...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits