'Parse Server: Is this an appropriate use case for relations?

I'm in the middle of a refactor and trying to make my database schema easier to understand by separating some things that used to travel together. But I'm concerned about abusing queries because I don't know how expensive they are.

For the purpose of this question, I'll say that my aim is to populate views that facilitate discussions about books. It's easier for me to understand if my schema looks like this:

Class Book

objectId name chapterDiscussionIds
abcdefgh book1 {ijklmnop,qrstuvwx}

Class ChapterDiscussion

objectId chapterContentId comments
ijklmnop a1b2c3d4 {commentId1,commentId2,commentId3}
qrstuvwx e5f6g7h8 {commentId4,commentId5}

Class ChapterContent

objectId text images footnotes
a1b2c3d4 "this is a chapter" {imageurl1,imageurl2} "a footnote"
e5f6g7h8 "another chapter" {imageurl3} ""

So here if my intention is to populate views with ChapterContent as well as ChapterDiscussion I'll have to do something like the following:

  1. query Books for chapterDiscussionIds of the correct book.
  2. query ChapterDiscussions for the commentIds and chapterContentIds
  3. query and render all comments
  4. query and render all chapter contents

Is this a situation where I can reduce the number of queries by using relations? Also, I intend to index each class to make these specific queries faster. So in a situation like that, is it ok to abuse queries and treat them like they're inexpensive?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source