任何人都知道如何在 QueryForTable 中缩小这个查询(使用 Parse.com)
Posted
技术标签:
【中文标题】任何人都知道如何在 QueryForTable 中缩小这个查询(使用 Parse.com)【英文标题】:Anyone know how to shrink this query in QueryForTable (using Parse.com) 【发布时间】:2012-12-20 10:14:49 【问题描述】:有人知道如何缩小这个,这样我就不必在 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 个元素,您可能需要使用内部查询返回的最大元素数;一路上的每个查询都受制于自己的查询限制。
【讨论】:
以上是关于任何人都知道如何在 QueryForTable 中缩小这个查询(使用 Parse.com)的主要内容,如果未能解决你的问题,请参考以下文章
queryForTable viewDidAppear、viewWillAppear 等不适用于子视图
任何人都知道如何在受众网络统一中使用 FBNativeAdBridgeCallback 函数
macOS - 任何人都知道在为 macOS 编程时如何在 Xcode 中缩放视图?
任何人都知道如何在 swift 操场上进行多项选择游戏? [关闭]