I have an activity table which says which users follows who. (fromUser
and toUser
)
I am constructing a leaderboard to see who has the most rating posted, amongst the followers.
So I created this query:
ParseQuery<ParseObject> queryActivityFollowing = new ParseQuery<>("Activity");
queryActivityFollowing.whereEqualTo("type", "follow");
queryActivityFollowing.whereEqualTo("fromUser", ParseUser.getCurrentUser());
queryActivityFollowing.setLimit(500);
// innerQuery, only get Users posted by the users I follow
ParseQuery<ParseUser> queryUserFollowing = ParseUser.getQuery();
queryUserFollowing.whereMatchesQuery("toUser", queryActivityFollowing);
// querySelf
ParseQuery<ParseUser> querySelf = ParseUser.getQuery();
querySelf.whereEqualTo("objectId", ParseUser.getCurrentUser().getObjectId());
List<ParseQuery<ParseUser>> queries = new ArrayList<>();
queries.add(queryUserFollowing);
queries.add(querySelf);
query = ParseQuery.or(queries);
query.orderByDescending("rating_count");
query.setLimit(20);
But somehow, it times out and never displays a result. Is there something inefficient with my query?
Thanks!
Edit:
Data description:
Activity
is a class with 3 columns, fromUser
, toUser
, type
. fromUser
and toUser
are pointers to the _User
class, type
is a string
in _User
, I have the classic attributes, and an integer named rating_count
, to which is the orderBy criteria (updated code above).
Actually, I think the query doesn't time out, but just returns 0 results. I follow some of my users so it's definitely not the expected output.