Copied to clipboard

Flag this post as spam?

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


  • Russell McGinnis 48 posts 183 karma points
    Jul 29, 2014 @ 22:33
    Russell McGinnis
    0

    Select first n Child Documents Efficiently

    I am using Umbraco V7 and struggling with an efficient way to find the first 5 child documents, within a document, efficiently.

    I have a NewsOverview document that contains over 60 NewsItem documents.

    I then have various partial views (Razor) that find the NewsOverview document and attempt to find the first 5 NewsItems to display as summaries, using the following code:

        var newsItems = newsOverview.newsItems.OrderBy("publishDate desc, createDate desc").Take(5);

    However, this has to load all of the NewsItems into memory before it can select the first 5 and this is a slow task.
    Any suggestions on a more efficient way to carry out this task ?
  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Jul 30, 2014 @ 17:47
    Jeavon Leopold
    101

    Hi Russell,

    PublishedContent is already cached in memory, I think that using the strongly typed model (Model.Content) might be a little more efficient than use the Dynamic model (CurrentPage).

    I'm not sure how your getting newsOverview, so the below is just a example:

    var newsOverview = Umbraco.TypedContent(1234);
    
    var newsItems = newsOverview.Children.OrderByDescending(x => x.UpdateDate).ThenByDescending(x => x.CreateDate).Take(5);        
    

    }

    Jeavon

  • Russell McGinnis 48 posts 183 karma points
    Jul 31, 2014 @ 19:01
    Russell McGinnis
    0

    Jeavon, thanks for the reply and the information. I was missing the fact that Umbraco caches it's content in memory and as such is not making heavy database calls.

    Been working with Umbraco (7) for 6 weeks now and loving how easy it is to work with. 

    Thanks

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Jul 31, 2014 @ 19:07
    Jeavon Leopold
    0

    That's fantastic to hear!

  • 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