How to count the number of pages under a certain path which uses a particular template? | Community
Skip to main content
Level 2
September 7, 2023
Solved

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

  • September 7, 2023
  • 6 replies
  • 2216 views

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  

    

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Harwinder-singh

@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#purpose

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

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

 

 

6 replies

Saravanan_Dharmaraj
Community Advisor
Community Advisor
September 7, 2023

@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.

 

 

 

aanchal-sikka
Community Advisor
Community Advisor
September 7, 2023

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
Preetpal_Bindra
Community Advisor
Community Advisor
September 7, 2023

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

 

Harwinder-singh
Community Advisor
Harwinder-singhCommunity AdvisorAccepted solution
Community Advisor
September 8, 2023

@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#purpose

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

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

 

 

Shashi_Mulugu
Community Advisor
Community Advisor
September 9, 2023

@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

kautuk_sahni
Community Manager
Community Manager
September 11, 2023

@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