Performance considerations when using OnlineDB
When using OnlineDB
in your application, please consider the following when it comes to your app’s performance:
- Limit
OnlineDB
calls and use .include().- Avoid repeating
OnlineDB
calls. Make use of variables so you can limit the overall number ofOnlineDB
calls you are making. - Note that any
belongs-to
calls on an object that was queried usingOnlineDB
will be anotherOnlineDB
call.- This is especially relevant in object tables. If you are using an
OnlineDB
query for an object table, avoid displaying relationships within the table if you have a large number of objects being displayed as each cell will be an additionalOnlineDB
call. - For example, in the following code there are two OnlineDB calls being made:
- This is especially relevant in object tables. If you are using an
- Avoid repeating
var job = OnlineDB.job.first();
var world_area = job.world_area();
- If querying a relationship, use the foreign key rather than calling the
belongs-to
function to decrease the number ofOnlineDB
calls.- For example, if you’re looking to find an office’s primary contact based on the current user’s office location, use Option 1 rather than Option 2.
Option 1:
var primary_contact = OnlineDB.primary_contact.where('office_id = ?', user.office_id);
Option 2:
var primary_contact = OnlineDB.primary_contact.where('office = ?', user.office());
- Avoid
OnlineDB
calls within XML functions as these functions are continuously evaluated. - Use cloud indexes.
Defining Sync Rules for applications that utilizes OnlineDB
Reference the Tips for Defining Sync Rules in Online-only Applications section of this post.
Handling OnlineDB Rate Limits
Reference this post.