Using Performant XPath Querying To Get Back Child Nodes By Path
I am trying to ensure my Umbraco site is using the most efficient way to get back large sets of data as the site grows. From reading the Common Pitfalls documentation, querying via XPath seems the way to go.
I understand how to get back all documents based on a property or alias. However, I cannot seem to find a way to get back documents based on a path using ContentAtXPath method.
In V7 and previous versions the published cache of content was stored as an XML file in memory, and consequently XPATH was generally always the quickest fastest way to retrieve things...
... But in V8 the published cache is stored using a new NuCache mechanism which is not in XML format, (XPATH has been retained, for some of the concepts in Umbraco like 'setting the start node in a multinode tree picker' - but it is no longer suggested to use XPATH for querying on your site implementation - you can - but it's no longer the 'quickest' method.
The common pitfalls documentation hasn't been updated for V8!
Paul Seal and Tim Payne gave a talk at Umbraco Spark - earlier this year regarding their investigations into peformance and querying in V8 and their slides are available here;
The slides have some useful examples, and show the timings of accessing content in different ways between V7 and V8.. showing of the places where certain strategies are faster than others.
Thanks for the additional info and I have just gone through Paul and Tim's slides.
Just to be sure I am understanding correctly, LINQ operations seem to be quicker in all the performance tests. So if I had 5000 pages and needed to do the following query:
You can always measure how long a piece of code takes to execute on your site, using the MiniProfiler: and wrapping the lines of code in an IProfiler 'step'
This is just a thought, and don't know if it will work, but if you put the take / skip before the .DescendantsOfType("blogpost") does it still loop through all the nodes?
Using Performant XPath Querying To Get Back Child Nodes By Path
I am trying to ensure my Umbraco site is using the most efficient way to get back large sets of data as the site grows. From reading the Common Pitfalls documentation, querying via XPath seems the way to go.
I understand how to get back all documents based on a property or alias. However, I cannot seem to find a way to get back documents based on a path using
ContentAtXPath
method.Umbraco.ContentAtXPath("//* [@isDoc]/descendant::/Blog [@isDoc]")
I am trying to run that within a SurfaceController.
I've seen other posts where quite nice querying was carried out in older versions of Umbraco including sorting etc.
I'd appreciate if someone could point me in the right direction.
Hi SSB85
It's all change in Umbraco V8!!
In V7 and previous versions the published cache of content was stored as an XML file in memory, and consequently XPATH was generally always the quickest fastest way to retrieve things...
... But in V8 the published cache is stored using a new NuCache mechanism which is not in XML format, (XPATH has been retained, for some of the concepts in Umbraco like 'setting the start node in a multinode tree picker' - but it is no longer suggested to use XPATH for querying on your site implementation - you can - but it's no longer the 'quickest' method.
The common pitfalls documentation hasn't been updated for V8!
Paul Seal and Tim Payne gave a talk at Umbraco Spark - earlier this year regarding their investigations into peformance and querying in V8 and their slides are available here;
https://umbracospark.com/media/p0xgaq2u/querying-umbraco.pptx
The slides have some useful examples, and show the timings of accessing content in different ways between V7 and V8.. showing of the places where certain strategies are faster than others.
regards
Marc
Hi Marc!
Thanks for the additional info and I have just gone through Paul and Tim's slides.
Just to be sure I am understanding correctly, LINQ operations seem to be quicker in all the performance tests. So if I had 5000 pages and needed to do the following query:
That wouldn't considered bad practice as I am getting backing all the types of "blogpost", just getting back 5 items and then ordering?
Hi SSB85,
Yes, I think that is the conclusion they came to.
You can always measure how long a piece of code takes to execute on your site, using the MiniProfiler: and wrapping the lines of code in an IProfiler 'step'
https://our.umbraco.com/documentation/Getting-Started/Code/Debugging/#writing-to-the-miniprofiler
But although it goes against all the ingrained Umbraco knowledge of previous versions, Linq with NuCache is the suggested approach.
If you are filtering by 'text' eg Where(f=>f.Value
... it depends on the context, but if you use the Miniprofiler you can be sure in your context what the expense of a particular query is.
regards
Marc
This is just a thought, and don't know if it will work, but if you put the take / skip before the .DescendantsOfType("blogpost") does it still loop through all the nodes?
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.