Sling model - multiple invocation | Community
Skip to main content
Level 2
February 12, 2021
Solved

Sling model - multiple invocation

  • February 12, 2021
  • 3 replies
  • 2979 views

Hello All, 

 

 We have an issue with 1 of our "card list" components. The card list model fires a AEM query using query builder API to get a list of pages under the current locale node with a particular template type. This result is then iterated to retrieve some properties like Title, Desc, Image, Authors, Date Published etc.. This is then rendered in HTML by HTL with expressions. We are using a max limit on the query to 100.

 

The component works as expected, however we are observing the Sling model is being instantiated twice. This is adding extra load to the server and negatively impacting the page load performance as well. Further on analysis, we observed removing the img tag in the component fixes the issue. Just adding the img tag ( even with hard coded url instead of sling model reference) causes the issue. We are using 6.4.8.

 

Any ideas what could be causing this issue would help our investigations.

 

Thanks

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 Shashi_Mulugu

@remakj can you post your HTL code maybe with dummy references also fine..

 

Without calling sling model twice in HTL or without adding more than one component of same type to page, I don't see any possibility of calling sling model twice.

3 replies

VeenaVikraman
Community Advisor
Community Advisor
February 16, 2021

To understand how you have implemented your component , your Card List component has a Sling Model, which internally query as you mentioned right ? 

 

If that is the case how the image tag is invoking the sling model ? 

remakjAuthor
Level 2
February 16, 2021
Hi Veena, Your understanding is correct. The Sling model in its PostConstruct method does the query and populate a list. This is used with in the Sightly template to render the list. I am not sure how the image tag is invoking the Sling Model as well. All I can find out is removing the tag causes the Sling model to be triggered once.
Shashi_Mulugu
Community Advisor
Shashi_MuluguCommunity AdvisorAccepted solution
Community Advisor
February 17, 2021

@remakj can you post your HTL code maybe with dummy references also fine..

 

Without calling sling model twice in HTL or without adding more than one component of same type to page, I don't see any possibility of calling sling model twice.

Ankur_Khare
Community Advisor
Community Advisor
February 17, 2021

Could you please add the code so that we can check how it's getting called twice as it's not possible until its called twice.