Question about URLs and performance

Tom Troughton asked on September 16, 2015 13:32

I've been investigating the slow performance of a Kentico site and have found in large part it's due to URL generation.

After some research a few months ago I found what seemed to be the consensus that the best approach to getting a document's URL in the API was to use TreePathUtils.GetDocumentUrl. I'd implemented this wherever I needed a URL in my custom web parts. However, on inspection it looks like this is hitting the database at least twice for every document. Since I have a custom menu web part with potentially dozens of links, that's a lot of additional trips to the database. What's more, Kentico doesn't appear to be performing any caching itself of the data that method is retrieving, because refreshing the page performs all the same SQL queries.

My first question is: is there a better performing way to get a document's URL? I should point out here that my URLs must be derived from document names, not page aliases. So on a multi-language site I need my news page to be available in default culture as and in French as I'm looking for a solution to generated such URLs without an additional trip to the database.

Any ideas?

Correct Answer

Dawid Jachnik answered on September 16, 2015 15:53

Hello Nat,

How you retive these documents from database? Why don't you include the "navigation" columns in it ? If you retrive these columns you can use this:

CMS.DocumentEngine.DocumentURLProvider.GetUrl("NodeAliasPath", null, "SiteName");

Which doesn't hit another time to database for data.

2 votesVote for this answer Unmark Correct answer

Recent Answers

Brenden Kehren answered on September 16, 2015 14:19

If you've created a custom webpart for navigation what does it consist of? Are you using the API? Have you included caching within your webpart? If not then you need to. Any custom development just introduces potential for additional errors and performance issues.

0 votesVote for this answer Mark as a Correct answer

Tom Troughton answered on September 16, 2015 18:01

@Brenden: Yes, using the API. Yes, caching TreeNode objects required by menu using caching API. I have reservations about using built-in Kentico components except where necessary and accept this means compromises. I maintain that large enterprises are rarely going to accept the limited behaviour of generic Kentico web parts unless they're somewhat limited in imagination.

@Daxid: That's the method I was looking for. Thank you. Must say I'm mystified by the sheer number of different methods and helpers in the Kentico API which often perform very similar tasks. TreeNodeProvider vs DocumentHelper for instance!

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.