iOS Parse.com 内部查询不会获取所有对象 [英] iOS Parse.com inner query doesn't fetch all objects

查看:16
本文介绍了iOS Parse.com 内部查询不会获取所有对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 parse.com 内部查询时遇到问题.这是我的代码.

 PFQuery *innerQuery = [PFUser 查询];[innerQuery whereKey:@"deactive" equalTo:[NSNumber numberWithBool:NO]];PFQuery *query = [PFQuery queryWithClassName:@"Post"];[查询 orderByDescending:@"voteCount"];[查询 setLimit:1];[查询 whereKey:@"user" 匹配查询:innerQuery];[查询 findObjectsInBackgroundWithBlock:^(NSArray 对象,NSError 错误) {//一些代码}];

这里有一个问题.Parse.com 中的内部查询最大限制计数也是 1000.在我的代码中,在 User 类中检索 1000 个对象并在其中执行查询后.如果用户数超过1000,则其余其他用户不在内部查询中.所以我无法得到它的 voteCount 属性最大的 post 对象.

我该如何解决?在 Parse 上是不可能的吗?

解决方案

您需要在完成块内重新启动查询.

如果您有 1000 个结果,我们假设还有更多结果需要获取并使用新参数 skip 执行另一个查询.Skip 与您所知道的完全相同,但会skip X 第一个结果.

所以你的 limit 是 1000,result 是 1000,还有一个新的 query 要做.

您必须将 limit 值赋予您的 skip 值,以便为第二批跳过完全相同的数字(通常只是最大值,1000).

您重复此操作,直到您的 result 计数为 result超过 1000,这意味着没有更多的对象要获取.

设置跳过值与设置限制相同.

[查询 setLimit:1000];[查询 setSkip:1000];

或者如果你喜欢动态

[查询 setLimit:1000];[查询 setSkip:query.limit];

如果您不需要所有信息而只需要最重要的信息(通常只是最新的信息),那么您可以简单地对查询进行排序.

[查询 orderByAscending:@"createdAt"];//或降序,或updatedAt,或您自己的字段

您还可以使用谓词或更多排序描述符来减小请求的大小.

I am getting trouble with parse.com inner query using. Here is my code.

    PFQuery *innerQuery = [PFUser query]; 
    [innerQuery whereKey:@"deactive" equalTo:[NSNumber numberWithBool:NO]]; 
    PFQuery *query = [PFQuery queryWithClassName:@"Post"]; 
    [query orderByDescending:@"voteCount"]; 
    [query setLimit:1]; 
    [query whereKey:@"user" matchesQuery:innerQuery]; 
    [query findObjectsInBackgroundWithBlock:^(NSArray objects, NSError error) { 

        //some code 
    }]; 

Here is a problem. Inner query max limit count is 1000 as well in Parse.com. In my code, after retrieving 1000 objects in User class and execute query among them. If user count exceeds 1000, then rest other users are out of inner query. so I can't get post object which it's voteCount property is largest.

How can I resolve it? Is it impossible on Parse?

解决方案

You need to restart a query inside your completion block.

If you have 1000 results, we assume that there is more to fetch and do another query with a new parameter, the skip. Skip does the exact same as what you know but will skip the X first results.

So you have your limit of 1000, a result of 1000, and a new query to make.

You must give your limit value to your skip value, so you skip exactly the same number (usually just the max, 1000) for your second batch.

You repeat this until your result count is < than 1000, which means there aren't any more objects to fetch.

Setting the skip value is the same as setting the limit.

[query setLimit:1000];
[query setSkip:1000];

or if you like dynamicness

[query setLimit:1000];
[query setSkip:query.limit];  

EDIT : If you don't need all information but only the most important one (which is usually just the latest in date), then you can simply sort your query.

[query orderByAscending:@"createdAt"];   //or descending, or updatedAt, or your own fields

You can also use predicates or more sort descriptors to reduce the size of your request.

这篇关于iOS Parse.com 内部查询不会获取所有对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆