I am creating an app in which users can make posts and other users can like and comment over these posts.To achieve this facility i am using tables likes POSTS, LIKES, COMMENTS.(I am using parse.com database to store these table).
POSTS have fields like postId, content, userWhoMadeThePost, dateOfPosting
LIKES contains filelds as id, postOnWhichLikeWasMade (foreign key to POSTS(postId)), userWhoLiked, dateofLike
COMMENTS have id, content, postOnWhichCommentWasMade(foreign key to POSTS(postId)), userWhoCommented, dateOfComment
I want to retrieve most popular posts (posts with most no of likes and comments).
This would be simple, if you had control over the database, but doing this with Parse means that you have two main problems (one of which you already mentioned):
That being said I think (at least if you insist on using parse) you must add the 'noOfLikes' and 'noOfComments' columns to the Post object. Not only does it provide the only viable solution for retrieving N top posts (without getting all of them), but the actual risk of inconsistencies is pretty low in my opinion. You can always catch network (or other) exceptions and temporarely store the update requests locally and retry them later.