Copied to clipboard

Flag this post as spam?

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


  • Hubert Thalmann 57 posts 263 karma points
    Sep 18, 2019 @ 07:58
    Hubert Thalmann
    0

    Get Nodes with Where Clausel by MultiNodeTreePicker

    Hello Umbraco Community

    I have a problem with looping trough about 1400 nodes. Its very slow and my page has long loading-times.

    The thing is that i only need the nodes where at the "Multinode Treepicker" is picked the current page. which is this Statement at the moment:

    if (komponist.Name == Model.Content.Name)
                                                    {
                                                        isKomponist = true;
                                                    }
    

    Here is the full code:

    @foreach (var eachKomposition in Umbraco.Content(1075).Children().Where("Visible"))
                                        {
                                            IPublishedContent kompositionModel = (IPublishedContent)eachKomposition;
                                            bool isKomponist = false;
                                            if (kompositionModel.HasValue("komponist"))
                                            {
                                                var komponistenTreePicker = kompositionModel.GetPropertyValue<IEnumerable<IPublishedContent>>("komponist");
                                                foreach (var komponist in komponistenTreePicker)
                                                {
                                                    if (komponist.Name == Model.Content.Name)
                                                    {
                                                        isKomponist = true;
                                                    }
                                                }
                                            }
                                            if (isKomponist)
                                            {
    
                                                <div class="filtertest" data-komponist="@kompositionModel.Name">
                                                    <a href="@kompositionModel.Url">
                                                        <div class="kompRow centermobile">
                                                            <div class="row">
                                                                <div class="col-12 col-12">
                                                                    @kompositionModel.Name
                                                                </div>
                                                                <div class="goto">
                                                                    Ansehen &raquo;
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </a>
                                                </div>
                                            }
                                        }
    

    Is there a way where i don't have to loop trough all nodes and then check for this selected item in the multinode tree picker, so that i only loop trought the nodes where this condition is true?

    my idea would be something like (pseudocode):

    @foreach (var eachKomposition in Umbraco.Content(1075).Children().Where(Value("komponist")[0].Id == Model.Content.Id)

    is there a way to do this?

    thanks in advance for helping

    Kind regards Hubert

  • Shaishav Karnani from digitallymedia.com 354 posts 1638 karma points
    Sep 18, 2019 @ 11:32
    Shaishav Karnani from digitallymedia.com
    1

    Hi Hubert,

    Below query will help you. @foreach (var eachKomposition in Umbraco.Content(1075).Children().Where(x=> x.HasValue("komponist") && x.GetPropertyValue<>

    // Above is more of a pseudo but will give you the logic to use.

    In addition, please try and use Html.CachedPartial and get this code inside that partial so it is all cached.

    This will reduce the repeated workload for your server and make site much fast.

    Cheers, Shaishav

  • Hubert Thalmann 57 posts 263 karma points
    Sep 18, 2019 @ 16:24
    Hubert Thalmann
    0

    Thanks i will give this query a try.

    And with Html.CachedPartial how often will the cache be refreshed? Everytime i publish a new node/edit a node? Or is this in a timespan?

Please Sign in or register to post replies

Write your reply to:

Draft