1
votes

Hi I know most probably this query was asked. How can I improve query performance on Sitecore queries. I've installed dotTrancer and got the results you can see into this image. My method with I did not displayed in the image tooked 2,551 ms and Sitecore query toked 2,344 ms which is huge. I am using Sitecore 7.2 i think their are around 10k item records into the database. We don't have more then 5 version per item. The query we do is:

return rootItem.Axes.SelectSingleItem(string.Format("descendant::*[@@{0}='{1}']", attributeName, attributeValue));

attributeName = TemplateName.

Do you have any ideas how I can optimize the request?

1

1 Answers

4
votes

Do not use Sitecore API for search. Use Sitecore Search:

public void Search(Item rootItem, string templateName)
{
    var index = ContentSearchManager.GetIndex("sitecore_" + Sitecore.Context.Database.Name + "_index");
    using (var context = index.CreateSearchContext())
    {
        var result = context.GetQueryable<SearchResultItem>().FirstOrDefault(i => i.TemplateName == templateName && i.Paths.Contains(rootItem.ID));
        if (result != null)
        {
            Item resultItem = result.GetItem();
        }
    }
}