Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

How to count the number of pages under a certain path which uses a particular template?

Avatar

Level 2

Hi Team,

I have some doubt, so I have content path (/content/my-project) under which I have to count the number of pages which uses a particular template. Under content path we have some sub sections like 

/content/my-project

    - /content/my-project/images

    - /content/my-project/propertyimages

    - /content/my-project/siteimages 

 

and each sub section contains thousands-millions of pages. I am using Query Builder to count the pages but it's putting lot of load on the environment and process is quite slow.

Is there some other optimized or efficient way I can achieve this.

 

@arunpatidar   @lukasz-m   @kautuk_sahni 

@SivakumarKanoori @Fanindra_Surat @krati_garg @iamnjain @somen-sarkar @bajancherry @sunil_kumar_  @shelly-goel @Ganthimathi_R @davidjgonzalezzzz @krishna_garikapati   @Shubham_borole @milind_bachani @krishna_sai @manjunathdj  

    

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@AditiSi You can make use of Fast Action manager(FAM) coupled with a visitor pattern based tree traversal.

Essentially, FAM is an API build on top of the ThrottledTaskRunner that is in turn build on the Java Management API.

Resource visitor pattern allows you to traverse a tree in multiple ways(depth First, breadth First).

For your use case, I would recommend creating a Managed controlled process (MCP) and make use of the above two features.

For that you will just need a latest version of ACS commons installed on your environment.

 

More details on all of this : 

https://adobe-consulting-services.github.io/acs-aem-commons/features/fast-action-manager/index.html#...

https://kiransg.com/tag/abstractresourcevisitor/

https://kiransg.com/tag/throttled/#:~:text=Throttled%20Task%20Runner%20(a%20managed,the%20actual%20w....

 

 

View solution in original post

6 Replies

Avatar

Community Advisor

@AditiSi Could you check the index is used when you executed the query or do you see traversal error in log.

You can diagnose the query by running the query performance tool./libs/granite/operations/content/diagnosistools/queryPerformance.html 

 

If this is the index issue , you can create the index using oak index generator.

https://oakutils.appspot.com/generate/index

and then run the query and see.

 

 

 

Avatar

Community Advisor

Hello @AditiSi 

 

There are multiple options:

 

1. Optimize index to use with queryBuilder. Which means assure cq:template property is indexed.

- OOTB this property is not part of cqPageLucene

2. Use Groovy scripts to traverse through tree and find all pages corresponding to a template:

- Sample code is available on https://hashimkhan.in/aem-adobecq5-code-templates/groovy-script/

- Groovy console can be installed from here

- No updates are required on the index.

 

 

 


Aanchal Sikka

Avatar

Community Advisor

What is the use case we're trying to solve here?

Would the page count be presented on the website or is it something that is one-time download kind of a need, like a report?

What is the frequency of updates to the page publication? Is it once a day, once a week?

Who are the consumers for this info? Is it content authors or website visitors?

 

What I'm trying to get to is to try & explore other potential ways to approach the problem.

 

regards,

Preetpal

 

Avatar

Correct answer by
Community Advisor

@AditiSi You can make use of Fast Action manager(FAM) coupled with a visitor pattern based tree traversal.

Essentially, FAM is an API build on top of the ThrottledTaskRunner that is in turn build on the Java Management API.

Resource visitor pattern allows you to traverse a tree in multiple ways(depth First, breadth First).

For your use case, I would recommend creating a Managed controlled process (MCP) and make use of the above two features.

For that you will just need a latest version of ACS commons installed on your environment.

 

More details on all of this : 

https://adobe-consulting-services.github.io/acs-aem-commons/features/fast-action-manager/index.html#...

https://kiransg.com/tag/abstractresourcevisitor/

https://kiransg.com/tag/throttled/#:~:text=Throttled%20Task%20Runner%20(a%20managed,the%20actual%20w....

 

 

Avatar

Community Advisor

@AditiSi can you post your query used to fetch pages as per your requirement so that we all can guide first if the query is optimized and can also suggest which index it has potential to pickup, may be a screenshot from explain query tool can help

Avatar

Administrator

@AditiSi Do you find the suggestions from users useful? Please let us know if more information is required. Otherwise, please mark the answer as correct for posterity. 



Kautuk Sahni