ios - 任何人都知道如何在 QueryForTable 中缩小此查询(使用 Parse.com)

标签 ios parse-platform

有人知道如何缩小它,这样我就不必在 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;

最佳答案

如果我没看错的话,您想要查询关注者或您附近的所有照片。为什么不使用:

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 个元素,则可能需要考虑内部查询返回的最大元素数;一路上的每个查询都受其自己的查询限制的约束。

关于ios - 任何人都知道如何在 QueryForTable 中缩小此查询(使用 Parse.com),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13969823/

相关文章:

ios - 由于 RealmSwift,当 swift 3 @obj 推理设置为 "default"时,应用程序崩溃

android - 解析 SDK Android Proguard 问题

ios - 是否可以使用 PFUser 的两个子类?

ios - 解析。保持 LocalDataStore 数据同步

java - 从 Parse.com 查询返回字符串

ios - 在编辑模式下滑动删除不起作用

ios - 从 superView 的 ViewController 之外的类调用时 willRemoveSubview 不会删除 subview ?

ios - Cloudkit:CKDatabaseOperation 不适用于蜂窝网络

ios - PDF 格式的新标签栏图标...创建自定义的指南?

android - 如何注册我的 Android 应用程序以解析网站