I'm attempting to do get the most recent comments of each result of a query using an OR query because promises are slow and expensive:
var queries = [];
_.each(videos, function (video) {
var mostRecentCommentsQuery = video.relation("comments").query();
mostRecentCommentsQuery.descending("createdAt");
mostRecentCommentsQuery.include("creator");
mostRecentCommentsQuery.include("mentions");
mostRecentCommentsQuery.limit(4);
queries.push(mostRecentCommentsQuery);
});
var commentQuery = new Parse.Query.or.apply(this, queries);
return commentQuery.find();
And getting this error:
Failed with: TypeError: function apply() { [native code] } is not a constructor
at Parse.Promise.when.then.then.then.next_page (functions.js:82:28)
at e (Parse.js:2:3909)
at Parse.js:2:3459
at Array.forEach (native)
at Object.x.each.x.forEach [as _arrayEach] (Parse.js:1:664)
at c.extend.resolve (Parse.js:2:3410)
at i (Parse.js:2:2901)
at b.Promise.is.a.then.g.(anonymous function) (Parse.js:2:2992)
at e (Parse.js:2:3909)
at Parse.js:2:3459
But doing var commentQuery = Parse.Query.or.apply(this, queries);
does nothing. Any suggestions?
EDIT:
I fixed the initial part; I never checked to make sure that comments had associations to the video's that own them. Unfortunately, this lead to a new issue, where the queries are not limited. EG:
There are 6 comments on the first video that is returned. The 4 most recent comments should be returned. All 6 are returned, which can lead to slow response times and plain inaccurate data.
Is there a way to enforce the limit of each subquery within an OR
query?
您可以对组合查询设置限制:即
commentQuery.limit(4);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.