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

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

问题描述

我在使用parse.com内部查询时遇到了麻烦.这是我的代码.

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 
    }]; 

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

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.

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

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

推荐答案

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

You need to restart a query inside your completion block.

如果您有1000个结果,则假定还有更多要提取的内容,并使用新参数 skip 进行另一个查询. Skip 与您所知道的完全相同,但是会跳过 X个优先结果.

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.

因此,您的 limit 为1000, result 为1000,并且要进行新的 query .

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

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

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.

重复此操作,直到您的结果计数为<超过1000,这意味着不再有要提取的对象.

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];

或者如果您喜欢动态性

[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天全站免登陆