Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • lori ryan 239 posts 573 karma points
    Dec 11, 2019 @ 10:13
    lori ryan
    0

    Controller

    Just wondering what's the best way to get all nodes of type xxx in a surface controller

    Am currently using

     IEnumerable<IPublishedContent> myIeNumerable = Umbraco.ContentAtXPath("//xxxx");
    

    Best approach??

  • Zoran Latinovic 6 posts 86 karma points
    Dec 11, 2019 @ 11:27
    Zoran Latinovic
    0

    Hi lori ryan

    You can use Umbraco extension method DescendantsOrSelf

  • Lars Heesakkers 38 posts 194 karma points
    Dec 13, 2019 @ 14:12
    Lars Heesakkers
    1

    Hi lori ryan,

    I recently found a article about the performance on the different ways of querying Umbraco : https://skrift.io/articles/archive/testing-the-performance-of-querying-umbraco/

    The article is written for Umbraco 7, but i assume it's also relevant for 8.

  • Mario Lopez 168 posts 958 karma points MVP 4x c-trib
    Dec 15, 2019 @ 22:43
    Mario Lopez
    0

    I recommend you to use Examine. It's the best performance way:

    public IEnumerable<Location> GetAllLocations()
    {
        var examineSearcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
        var searchCriteria = examineSearcher.CreateSearchCriteria(Examine.SearchCriteria.BooleanOperation.And);
        var searchQuery = searchCriteria.NodeTypeAlias(Location.ModelTypeAlias);
        var locations = Umbraco.TypedSearch(searchQuery.Compile()).Cast<Location>();
    
        return locations;
    }
    

    EDIT: Don't ever use DescendantsOrSelf. If you do that from the site's root you can end up with hundreds or thousands or nodes loaded into memory.

  • Zoran Latinovic 6 posts 86 karma points
    Dec 16, 2019 @ 09:08
    Zoran Latinovic
    0

    Based on article that Lars suggested most efficient way is with Umbraco.ContentAtXPath("//xxxx");

    Event DescendantsOrSelf is faster than Umbraco.TypedSearch

  • Lars Heesakkers 38 posts 194 karma points
    Dec 16, 2019 @ 09:15
    Lars Heesakkers
    0

    I have to agree with Mario that you have to be extremely careful with DescendantsOrSelf, especially with large amount of nodes.

    I also remember Umbraco.ContentAtXPath being the faster one.

  • Mario Lopez 168 posts 958 karma points MVP 4x c-trib
    Dec 17, 2019 @ 03:00
    Mario Lopez
    0

    You're right, I thought TypedSearch performed better. Still you can use Examine with Take and Skip to improve the query.

    I guess it depends how many nodes you expect to have. If you have a News section for instance, that can grow a lot, I wouldn't go with the DescendantsOrSelf option or the Xpath.

  • 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.

Please Sign in or register to post replies