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 ?
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, 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.
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);
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:
}
Jeavon
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
That's fantastic to hear!
is working on a reply...