Cloud Connected

Query Performance

Application queries

Application code which consumes Cloud CMS content typically runs query API calls. These queries can be optimized in the following ways:

Request only the properties needed

When an application requires only a few properties from a set of nodes you should use “_fields” to limit the properties returned. This can drastically reduce the size of the payload and therefore the response time. In this example, we only need “_doc”, “title” and “_type” so these are the only fields that will be returned.

let result = await cloudcmsSession.queryNodes(repository, branch, { _type: "custom:blogpost", tags: “tag1”, _fields: { _type: 1, title: 1 } }); Note that “_doc” does not have to be included in the “_fields” list. It is always included by default.

Use indexes

Cloud CMS allows you to create custom indexes on content stored in MongoDB. When you know what the queries used in your application look like you can improve the response to those queries using indexes. Whenever a query is sent to MongoDB it will look for an index that can be used to optimize the query. Create the index by including the properties you use in the select part of the query plus any fields you sort on. Given the query from above, the index could look like this: { “_type”: 1, “tags”: 1 }