Copied to clipboard

Flag this post as spam?

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


  • Ruben Verhaaf 14 posts 34 karma points
    Mar 15, 2012 @ 14:48
    Ruben Verhaaf
    0

    DescendantContent() dreadfully slow

    Hi all,

    I am trying to display the last 5 news items. I can't manage to make it perform. Using DescendantContent on the root node (which I get by id, as I don't know any other way), the code below takes more than a second to run. 

    @{
        var rootNode = Hive.Content.GetById("35a2c47081bd45a4bcbd9fe400ccabb0");
        var actueelItems = rootNode.DescendantContent().Where(x => x.ContentType.Alias == "actueelItem").OrderByDescending(x => x.SortOrder).Take(5);
        var actueelList = actueelItems.ToList();
        if (actueelItems.Any())
        {
            <div class="greenBlock secondBlock leftCornerGreen actueel fixedHeightBlock">
                <h2 class="DIN">Actueel</h2>
                <table>
                    <tbody>
                        @foreach (var item in actueelItems)
                        {
                            var bentItem = item.Bend();
                            <tr>
                                <td class="datum">@bentItem.PublishingDate.ToString("dd-MM-yyyy")</td>
                                <td class="actueel-item"><a href="@Umbraco.GetUrl(@item)">@item.Name</a></td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
        }
    }

    I have tried to use the following line, only the resulting items don't have any properties such as Name or PublishingDate, and are not ordered or limited  yet. 

    var actueelItems = rootNode.Children().Where("ContentTypeAlias == @0", "actueelItem");

    How can I get the newest 5 content items of a certain content type anywhere in the tree (or in a specific node) in such a way that it performs, as well as contains the data accessible using the dot operator (item.PublishingDate)?

  • kevin 31 posts 52 karma points
    Mar 26, 2012 @ 15:49
    kevin
    0

    you can use ChildContent() instead of Children() to return Content items, that way you can access those properties

  • 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