Brion VIBBER has submitted this change and it was merged. Change subject: Fix for occasional crash when clearing saved pages. ......................................................................
Fix for occasional crash when clearing saved pages. Change-Id: I828294b6e0515d4a2d307a833581a5d0ea7de6f9 --- M wikipedia/Web Image Interception/URLCache.m 1 file changed, 24 insertions(+), 19 deletions(-) Approvals: Brion VIBBER: Verified; Looks good to me, approved diff --git a/wikipedia/Web Image Interception/URLCache.m b/wikipedia/Web Image Interception/URLCache.m index d764118..30e1d69 100644 --- a/wikipedia/Web Image Interception/URLCache.m +++ b/wikipedia/Web Image Interception/URLCache.m @@ -148,29 +148,34 @@ // Strip "http:" or "https:" imageURL = [imageURL getUrlWithoutScheme]; - - Image *imageFromDB = (Image *)[articleDataContext_.mainContext getEntityForName: @"Image" withPredicateFormat:@"sourceUrl == %@", imageURL]; - // If a core data Image was found, but its data length is zero, the Image record was probably - // created when the section html was parsed to create sectionImage records, in which case - // a request needs to actually be made, so set cachedResponse to nil so this happens. - // NSLog(@"imageFromDB.data = %@", imageFromDB.data); - if (imageFromDB && (imageFromDB.imageData.data.length == 0)) { - cachedResponse = nil; - }else if (imageFromDB) { - //NSLog(@"CACHED IMAGE FOUND!!!!!! requestURL = %@", imageURL); - NSData *imgData = imageFromDB.imageData.data; - NSURLResponse *response = [[NSURLResponse alloc] initWithURL:requestURL MIMEType:imageFromDB.mimeType expectedContentLength:imgData.length textEncodingName:nil]; - cachedResponse = [[NSCachedURLResponse alloc] initWithResponse:response data:imgData]; + [articleDataContext_.mainContext performBlockAndWait:^(){ - imageFromDB.dateLastAccessed = [NSDate date]; + Image *imageFromDB = (Image *)[articleDataContext_.mainContext getEntityForName: @"Image" withPredicateFormat:@"sourceUrl == %@", imageURL]; - NSError *error = nil; - [articleDataContext_.mainContext save:&error]; - if (error) { - NSLog(@"Error updating image dateLastAccessed in articleData store: %@", error); + // If a core data Image was found, but its data length is zero, the Image record was probably + // created when the section html was parsed to create sectionImage records, in which case + // a request needs to actually be made, so set cachedResponse to nil so this happens. + // NSLog(@"imageFromDB.data = %@", imageFromDB.data); + if (imageFromDB && (imageFromDB.imageData.data.length == 0)) { + cachedResponse = nil; + }else if (imageFromDB) { + //NSLog(@"CACHED IMAGE FOUND!!!!!! requestURL = %@", imageURL); + NSData *imgData = imageFromDB.imageData.data; + NSURLResponse *response = [[NSURLResponse alloc] initWithURL:requestURL MIMEType:imageFromDB.mimeType expectedContentLength:imgData.length textEncodingName:nil]; + cachedResponse = [[NSCachedURLResponse alloc] initWithResponse:response data:imgData]; + + imageFromDB.dateLastAccessed = [NSDate date]; + + NSError *error = nil; + [articleDataContext_.mainContext save:&error]; + if (error) { + NSLog(@"Error updating image dateLastAccessed in articleData store: %@", error); + } } - } + + }]; + if (cachedResponse) return cachedResponse; //NSLog(@"CACHED IMAGE NOT FOUND!!!!! request.URL = %@", imageURL); -- To view, visit https://gerrit.wikimedia.org/r/165668 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I828294b6e0515d4a2d307a833581a5d0ea7de6f9 Gerrit-PatchSet: 2 Gerrit-Project: apps/ios/wikipedia Gerrit-Branch: master Gerrit-Owner: Mhurd <mh...@wikimedia.org> Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits