Skip to content

Commit

Permalink
[ios-sdk] Place picker cache descriptor should use AsNeeded paging mo…
Browse files Browse the repository at this point in the history
…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
Chris Lang committed Aug 7, 2012
1 parent cc22139 commit 4318523
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
38 changes: 19 additions & 19 deletions samples/Scrumptious/scrumptious/SCViewController.m
Expand Up @@ -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;
Expand All @@ -58,6 +59,7 @@ - (void)updateCellIndex:(int)index withSubtitle:(NSString *)subtitle;
- (void)postPhotoThenOpenGraphAction;
- (void)postOpenGraphActionWithPhotoURL:(NSString *)photoID;
- (void)centerAndShowActivityIndicator;
- (void)setPlaceCacheDescriptorForCoordinates:(CLLocationCoordinate2D)coordinates;

@end

Expand All @@ -80,6 +82,7 @@ @implementation SCViewController
@synthesize activityIndicator = _activityIndicator;
@synthesize settingsViewController = _settingsViewController;
@synthesize mealTypes = _mealTypes;
@synthesize placeCacheDescriptor = _placeCacheDescriptor;

#pragma mark open graph

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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];
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/FBPlacePickerCacheDescriptor.m
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions src/FBPlacePickerViewController.m
Expand Up @@ -351,7 +351,6 @@ - (void)loadDataPostThrottleSkippingRoundTripIfCached:(NSNumber*)skipRoundTripIf
[self.loader startLoadingWithRequest:request
cacheIdentity:FBPlacePickerCacheIdentity
skipRoundtripIfCached:skipRoundTripIfCached.boolValue];
[self updateView];
}
}

Expand Down Expand Up @@ -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];
}
}
Expand Down

0 comments on commit 4318523

Please sign in to comment.