Best way (performance wise) to get a reference to the topmost node
Hi all,
I'm in a situation where I need to get a reference to the top-most (root) node from one of it childnodes (or maybe even grandchild nodes)
My structure is a as follows:
- da (site node with the property) - Childnode - Childnode
- en (site node) - Childnode - Childnode
On each of the site nodes there's a property that I need to read the value of on one/some of the child and/or childrens childnode(s) It's important that it reads the value of the correct site-node :-)
What I'm doing so far is using uComponents GetNodesByXPath() uQuery method. But there's two problems:
1) It takes 2 ~ 5 seconds to give me the result which is not ideal.
2) It returns the first site node in the tree
My code is as follows:
var siteRootNode = uQuery.GetNodesByXPath("//Site[@isDoc]").FirstOrDefault();
So, my question is: is there any other way to do this with performance in mind? :-) It's probably just me that don't know my XPath'ing too well ;-)
I'm suprised the GetNodesByXPath() method is slow ! the first hit will create a compiled XPath expression, so subsequent ones should be faster. (also if you have multiple 'Site' nodes, I the above XPath expression might not be returning the correct one)
An alternative approach could be to walk up the tree (just like Stefan suggests)
using System.Linq; using uComponents.Core.uQueryExtensions;
Thanks kipusoep and Hendy, greatly appreciated! :-)
Tried both of your methods and it turns out that it basically has nothing to do with the code I had (at least not the performance part of it) Also, I'd like to point out that it was not the uQuery Extension from uComponent that is slow! Very important to note that.
Still the problem persists. It feels like it's when the app pool has gone to sleep (for the lack of better sentence right now) and I hit one of the filter checkboxes, then the first search takes up to 5 seconds to give back the results. This search is done with Examine.
Does anyone know any way to increase the performance of the first examine search? It feels like *something* has to "wake up" before actually executing the search (?)
My examine (Razor) code is as follows and is called when a user checks/unchecks one or more checkboxes on the frontend:
@{
@* Get theme node ids from querystring *@
var themeIds = HttpContext.Current.Request.QueryString["themes"];
ISearchCriteria sc;
IBooleanOperation query;
IOrderedEnumerable<SearchResult> result = null;
@* Get current sites language *@
SiteLanguage siteLanguage = new SiteLanguage();
string language = siteLanguage.GetSiteLanguageByXPath(Model.Id);
if (!string.IsNullOrEmpty(language))
{
sc = ExamineManager.Instance.SearchProviderCollection["RecipeSearcher"].CreateSearchCriteria();
@* If no theme is chosen, render all recipes *@
if (!string.IsNullOrEmpty(themeIds))
{
@* Perform examine search *@
query = sc.NodeTypeAlias("Recipe").And().GroupedAnd(new[] { "selectedThemes" }, new[] { themeIds.TrimEnd(',') }).And().Field("_siteLanguage", language);
}
else
{
@* Perform examine search *@
result = ExamineManager.Instance.SearchProviderCollection["RecipeSearcher"].Search(query.Compile()).OrderByDescending(x => x.Id);
}
result = ExamineManager.Instance.SearchProviderCollection["RecipeSearcher"].Search(query.Compile()).OrderByDescending(x => x.Id);
@* Check if the search contains any elements *@
if (result != null && result.Count() > 0)
{
<div class="recipe-container">
@foreach (var recipe in result)
{
@* Output markup *@
<div class="recipe">
@if (recipe.Fields.ContainsKey("image"))
{
dynamic image = Library.MediaById(int.Parse(recipe.Fields["image"]));
<div><a href="@umbraco.library.NiceUrl(recipe.Id)"><img src="/[email protected]&width=213&height=169&compression=100" alt="@recipe.Fields["header"]" /></a></div>
}
<p><a href="#">@recipe.Fields["header"]</a></p>
</div>
}
</div>
<span style="display:none;" class="filter-count">@result.Count()</span>
@* TODO: Paging *@
}
else
{
<span style="display:none;" class="filter-count">0</span>
}
}
}
Just wondering - have you tried changing the Idel Time Out setting to 0 (zero) within the application pool (located under advanced settings) to see if this prevents the slow first response ?
Best way (performance wise) to get a reference to the topmost node
Hi all,
I'm in a situation where I need to get a reference to the top-most (root) node from one of it childnodes (or maybe even grandchild nodes)
My structure is a as follows:
- da (site node with the property)
- Childnode
- Childnode
- en (site node)
- Childnode
- Childnode
On each of the site nodes there's a property that I need to read the value of on one/some of the child and/or childrens childnode(s) It's important that it reads the value of the correct site-node :-)
What I'm doing so far is using uComponents GetNodesByXPath() uQuery method. But there's two problems:
1) It takes 2 ~ 5 seconds to give me the result which is not ideal.
2) It returns the first site node in the tree
My code is as follows:
So, my question is: is there any other way to do this with performance in mind? :-) It's probably just me that don't know my XPath'ing too well ;-)
Thanks a lot in advance,
Bo
Well, in C# I use this piece of code:
Hi Bo,
I'm suprised the GetNodesByXPath() method is slow ! the first hit will create a compiled XPath expression, so subsequent ones should be faster. (also if you have multiple 'Site' nodes, I the above XPath expression might not be returning the correct one)
An alternative approach could be to walk up the tree (just like Stefan suggests)
HTH,
Hendy
Thanks kipusoep and Hendy, greatly appreciated! :-)
Tried both of your methods and it turns out that it basically has nothing to do with the code I had (at least not the performance part of it) Also, I'd like to point out that it was not the uQuery Extension from uComponent that is slow! Very important to note that.
Still the problem persists. It feels like it's when the app pool has gone to sleep (for the lack of better sentence right now) and I hit one of the filter checkboxes, then the first search takes up to 5 seconds to give back the results. This search is done with Examine.
Does anyone know any way to increase the performance of the first examine search? It feels like *something* has to "wake up" before actually executing the search (?)
My examine (Razor) code is as follows and is called when a user checks/unchecks one or more checkboxes on the frontend:
Thanks a lot in advance.
All the best,
Bo
Hi Bo
Just wondering - have you tried changing the Idel Time Out setting to 0 (zero) within the application pool (located under advanced settings) to see if this prevents the slow first response ?
Cheers
Nigel
Good point there, Nigel. However, I don't have access to the IIS on the live environment :/
Will have to check if there's some kind of Umbraco setting that could do the trick :) Thanks again!
is working on a reply...