2012-12-20 2 views
0

QueryForTable 메서드의 주 스레드에서 쿼리를 실행할 필요가 없도록이 방법을 축소하는 방법을 알고 계십니까? Parse.com을 사용하고 있습니다.누구나 QueryForTable (Parse.com 사용)에서이 쿼리를 축소하는 방법을 알고

//Find who are the users following (RELATIONSHIP OBJECT) 
PFQuery *followeesQuery = [PFQuery queryWithClassName:@"Relationship"]; 
[followeesQuery whereKey:@"Follower" equalTo:[PFUser currentUser]]; 
NSArray *followees = [followeesQuery findObjects]; 
//Filter followees 
self.followees = [[NSMutableArray alloc] initWithCapacity:[followees count]]; 
for (int i = 0; i < [followees count]; i++) { 
    PFObject *followee = followees[i]; 
    PFUser *user = (PFUser *)[followee objectForKey:@"User"]; //USER OBJECT 
    [self.followees addObject:user]; 
} 


PFQuery *nearbyPhotosQuery = [PFQuery queryWithClassName:@"Photo"]; //PHOTO OBJECT 
[nearbyPhotosQuery whereKey:@"User" notContainedIn:self.followees]; 
[nearbyPhotosQuery whereKey:@"Location" nearGeoPoint:self.userCurrentLocation withinKilometers:10]; 

PFQuery *followersPhotoQuery = [PFQuery queryWithClassName:@"Photo"]; //PHOTO OBJECT 
[followersPhotoQuery whereKey:@"User" containedIn:self.followees]; 

NSMutableSet *set = [NSMutableSet setWithArray:[nearbyPhotosQuery findObjects]]; 
[set addObjectsFromArray:[followersPhotoQuery findObjects]]; 

NSArray *targetPhotoObjects = [set allObjects]; 

NSMutableArray *targetIDs = [[NSMutableArray alloc] initWithCapacity:[targetPhotoObjects count]]; 
for (int i = 0; i < [targetPhotoObjects count] ; i++) { 
    PFObject *photoObject = targetPhotoObjects[i]; 
    [targetIDs addObject:photoObject.objectId]; 
} 


PFQuery *targetPhotoQuery = [PFQuery queryWithClassName:@"Photo"]; 
[targetPhotoQuery whereKey:@"objectId" containedIn:targetIDs]; 


return targetPhotoQuery; 

답변

1

정확하게 읽으면 팔로워 또는 가까운 사람이 모든 사진에 대한 쿼리를 원합니다. 왜 사용하지 마십시오 :

PFQuery *followeesQuery = [PFQuery queryWithClassName:@"Relationship"]; 
[followeesQuery whereKey:@"Follower" equalTo:PFUser.currentUser]; 

PFQuery *followeesPhotosQuery = [PFQuery queryWithClassName:@"Photo"]; 
[followeesPhotosQuery whereKey:@"User" matchesKey:@"User" inQuery:followeesQuery]; 

PFQuery *nearbyPhotosQuery = [PFQuery queryWithClassName:@"Photo"]; 
[nearbyPhotosQuery whereKey:@"Location" 
       nearGeoPoint:self.userCurrentLocation 
      withinKilometers:10]; 

return [PFQuery orQueryWithSubqueries:@[followeesPhotosQuery, nearbyPhotosQuery]]; 

이것은 서버 측 트립을 만들 필요가없는 찾고자하는 것과 일치하는 쿼리입니다. 프로세스의 모든 단계에서 100 개가 넘는 요소가 반환 될 것으로 예상되는 경우 내부 쿼리에서 반환하는 요소의 최대 개수로 재생해야 할 수 있습니다. 도중의 각 쿼리는 자체 쿼리 제한의 영향을받습니다.

관련 문제