OnlineDB Best Practices

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 of OnlineDB calls you are making.
    • Note that any belongs-to calls on an object that was queried using OnlineDB will be another OnlineDB 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 additional OnlineDB call.
      • For example, in the following code there are two OnlineDB calls being made:
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 of OnlineDB 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 = ?',;
  • Avoid OnlineDB calls within XML functions as these functions are continuously evaluated.
  • Use cloud indexes.
    • See our documentation references here and here.

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.