Expand my Community achievements bar.

SOLVED

Performance

Avatar

Level 6

Hi Aem-community,

Is it better use node iterator or querybuilder to find components on page and get properties of components?

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

When you need to find that on a single page, use the iterator approach; the static overhead of queries is typically higher than the cost of iterating.

View solution in original post

4 Replies

Avatar

Community Advisor

@Keerthi0555 

It depends on couple of things: How complex is the query and how many nodes you are planning to traverse.

For a small number of nodes, iterating through JCR nodes using a node iterator is often more efficient.
For larger node sets or when dealing with more complex queries, it's generally better to set up Oak indexes and use QueryBuilder.
 
This best practices guides on queries and indexing might help, try checking this out 
 

Avatar

Community Advisor

@Keerthi0555 Node iteration is always faster and performance efficient that Query Builder. If you know the exact path to iterate and get the values , I would say use Node Iteration.  

 

Please find a more detailed explanation from @Jörg_Hoh https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/child-node-iterating/m-p/3... 

Avatar

Community Advisor

@Keerthi0555 

If you want to iterate through all the resources then go with iterator.

If you want a specific resource(s) with specific property then search using query builder.

Depends on your use case. 

Avatar

Correct answer by
Employee Advisor

When you need to find that on a single page, use the iterator approach; the static overhead of queries is typically higher than the cost of iterating.