Skip to content
Browse files

[ios-sdk] Place picker cache descriptor should use AsNeeded paging mo…

…de rather than ImmediateViewless.

Summary:
When caching place results, we do not want to automatically follow "next" links -- we only want to cache the first
page of results.

Test Plan:
- Ran Scrumptious, only saw one page worth of places being queried.

Revert Plan:

Reviewers: jacl, mmarucheck, gregschechte, ayden

Reviewed By: jacl

CC: msdkexp@

Differential Revision: https://phabricator.fb.com/D541068
  • Loading branch information...
1 parent cc22139 commit 43185236c101fc0ea4d27d358d656bb070febad1 @clang13 clang13 committed Aug 6, 2012
View
38 samples/Scrumptious/scrumptious/SCViewController.m
@@ -45,6 +45,7 @@ @interface SCViewController() < UITableViewDataSource,
@property (strong, nonatomic) NSArray *selectedFriends;
@property (strong, nonatomic) UIImage *selectedPhoto;
@property (strong, nonatomic) CLLocationManager *locationManager;
+@property (strong, nonatomic) FBCacheDescriptor *placeCacheDescriptor;
@property (strong, nonatomic) UIPopoverController *popover;
@property (strong, nonatomic) SCPhotoViewController *photoViewController;
@property (nonatomic) CGRect popoverFromRect;
@@ -58,6 +59,7 @@ - (void)updateCellIndex:(int)index withSubtitle:(NSString *)subtitle;
- (void)postPhotoThenOpenGraphAction;
- (void)postOpenGraphActionWithPhotoURL:(NSString *)photoID;
- (void)centerAndShowActivityIndicator;
+- (void)setPlaceCacheDescriptorForCoordinates:(CLLocationCoordinate2D)coordinates;
@end
@@ -80,6 +82,7 @@ @implementation SCViewController
@synthesize activityIndicator = _activityIndicator;
@synthesize settingsViewController = _settingsViewController;
@synthesize mealTypes = _mealTypes;
+@synthesize placeCacheDescriptor = _placeCacheDescriptor;
#pragma mark open graph
@@ -451,6 +454,15 @@ - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interface
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
+- (void)setPlaceCacheDescriptorForCoordinates:(CLLocationCoordinate2D)coordinates {
+ self.placeCacheDescriptor =
+ [FBPlacePickerViewController cacheDescriptorWithLocationCoordinate:coordinates
+ radiusInMeters:1000
+ searchText:@"restaurant"
+ resultsLimit:50
+ fieldsForRequest:nil];
+}
+
#pragma mark UITableViewDataSource methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
@@ -557,20 +569,16 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
FBPlacePickerViewController *placePicker = [[FBPlacePickerViewController alloc] init];
placePicker.title = @"Select a restaurant";
- placePicker.locationCoordinate = self.locationManager.location.coordinate;
- placePicker.radiusInMeters = 1000;
- placePicker.resultsLimit = 50;
- placePicker.searchText = @"restaurant";
-
+
// SIMULATOR BUG:
// See http://stackoverflow.com/questions/7003155/error-server-did-not-accept-client-registration-68
// at times the simulator fails to fetch a location; when that happens rather than fetch a
// a meal near 0,0 -- let's see if we can find something good in Paris
- if (!(placePicker.locationCoordinate.latitude ||
- placePicker.locationCoordinate.longitude)) {
- placePicker.locationCoordinate = CLLocationCoordinate2DMake(48.857875, 2.294635);
+ if (self.placeCacheDescriptor == nil) {
+ [self setPlaceCacheDescriptorForCoordinates:CLLocationCoordinate2DMake(48.857875, 2.294635)];
}
+ [placePicker configureUsingCachedDescriptor:self.placeCacheDescriptor];
[placePicker loadData];
[placePicker presentModallyFromViewController:self
animated:YES
@@ -639,17 +647,9 @@ - (void)locationManager:(CLLocationManager *)manager
(oldLocation.coordinate.latitude != newLocation.coordinate.latitude &&
oldLocation.coordinate.longitude != newLocation.coordinate.longitude &&
newLocation.horizontalAccuracy <= 100.0)) {
- // FBSample logic
- // If we already have a place picker, reload its data. If not, pre-fetch the
- // data so it is displayed quickly on first use of the place picker. Don't waste
- // time caching data if we aren't at our desired level of accuracy.
- FBCacheDescriptor *cacheDescriptor =
- [FBPlacePickerViewController cacheDescriptorWithLocationCoordinate:newLocation.coordinate
- radiusInMeters:1000
- searchText:@"restaurant"
- resultsLimit:50
- fieldsForRequest:nil];
- [cacheDescriptor prefetchAndCacheForSession:FBSession.activeSession];
+ // Fetch data at this new location, and remember the cache descriptor.
+ [self setPlaceCacheDescriptorForCoordinates:newLocation.coordinate];
+ [self.placeCacheDescriptor prefetchAndCacheForSession:FBSession.activeSession];
}
}
View
2 src/FBPlacePickerCacheDescriptor.m
@@ -88,7 +88,7 @@ - (void)prefetchAndCacheForSession:(FBSession*)session {
self.loader.delegate = nil;
self.loader = [[[FBGraphObjectPagingLoader alloc] initWithDataSource:datasource
- pagingMode:FBGraphObjectPagingModeImmediateViewless]
+ pagingMode:FBGraphObjectPagingModeAsNeeded]
autorelease];
self.loader.session = session;
self.loader.delegate = self;
View
3 src/FBPlacePickerViewController.m
@@ -351,7 +351,6 @@ - (void)loadDataPostThrottleSkippingRoundTripIfCached:(NSNumber*)skipRoundTripIf
[self.loader startLoadingWithRequest:request
cacheIdentity:FBPlacePickerCacheIdentity
skipRoundtripIfCached:skipRoundTripIfCached.boolValue];
- [self updateView];
}
}
@@ -484,7 +483,7 @@ - (NSString *)graphObjectTableDataSource:(FBGraphObjectTableDataSource *)dataSou
- (void)pagingLoader:(FBGraphObjectPagingLoader*)pagingLoader willLoadURL:(NSString*)url {
// We only want to display our spinner on loading the first page. After that,
// a spinner will display in the last cell to indicate to the user that data is loading.
- if (!self.dataSource.hasGraphObjects) {
+ if ([self.dataSource numberOfSectionsInTableView:self.tableView] == 0) {
[self centerAndStartSpinner];
}
}

0 comments on commit 4318523

Please sign in to comment.
Something went wrong with that request. Please try again.