Support Topics Documentation Slack YouTube Blog

How to optimize a Find query for a Hierarchy of objects to get all of the objects instead of just 10


(Jonathan ) #1

I am trying to find how to get an object and all of its hierarchy of relations in the least number of queries. There are 4 levels of relations. The size of the relation objects are no more than 20 items, some objects may only have fewer than 10 and others more, but the Backendless limit for number of relations is a maximum of 10. So I have to iterate at each level through each child object and get all of its relations, which ends up being a lot of calls.

Is there a more optimal query that I could make to solve this problem?

I’m doing this query in Javascript


Cannot load more than 10 records
(Mark Piller) #2

Even if that is possible, does your app really show that much information on a single screen? I think any drive to minimize the number of calls is likely to yield a substandard user experience.


(Jonathan ) #3

Mark, even with 2 levels of relations, say a single object has children objects who also have children objects. Is there a way to get this information with only 2 queries?


(Mark Piller) #4

Yes, you’d reference the relations in a DataQueryBuilder object in the format of firstLevelRelation, firstLevelRelation.secondLevelRelation. Here’s an example with REST:


(Jonathan ) #5

Doing it this way was what I originally had until I noticed I was only getting 10 objects back when I needed to get all 12. So that’s when I had to iterate through each object and get all of the children with the pageSize parameter.


(Mark Piller) #6

That’s correct, this is the built-in behavior. Loading additional objects would require a separate API call. To minimize the number of calls from the client-side perspective, you could shift that logic to Cloud Code which would be responsible for iterating over the collection and loading additional child objects to build the entire tree.


(Jonathan ) #7

Yes, Cloud Code is where I’m doing this logic. is there a service pricing plan that allows us to remove or adjust this restriction?


(Mark Piller) #8

Not in Backendless Cloud (shared app hosting). It can be done with Managed Backendless (dedicated app hosting) though.