Copied to clipboard

Flag this post as spam?

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


  • Christian Hansen 14 posts 85 karma points
    Sep 03, 2017 @ 18:21
    Christian Hansen
    0

    MerchelloHelper Query.Product slow performance ( Product variant specific description )

    Hello,

    I am using Umbraco 7.5.11 and Merchello 2.5.0 with FastTrack.

    I am experiencing significant slow loading (timed it to 23 sec load) on a page that uses mHelper.Query.Product.GetByKey(Model.Key); compared to mHelper.TypedProductContent(Model.Key); which is pretty much instant. The only reason I am using Query.Product is because it gives me access to product.DetachedContents that I need for accessing a product variant detached content for displaying specific product variant description. All my variants has their own unique description.

    Is there any other way I can access DetachedContents ? Or any other way to display product variant specific description?

    This is my code in Views/_ProductBox.cshtml

    @inherits UmbracoViewPage<Merchello.Web.Models.VirtualContent.IProductContent>
    @using Merchello.Core
    @using Merchello.Web.Store.Controllers
    @using Merchello.FastTrack.Ui
    @using Merchello.Web
    
    @{ 
        var mHelper = new MerchelloHelper();
    
        //var product = mHelper.TypedProductContent(Model.Key);
        var product = mHelper.Query.Product.GetByKey(Model.Key);
    
        var hasVariants = product.ProductVariants.Any();
        var doesHaveDetachedContents = false;
        var lastVariantID = "";
    
    }
    
    <div id="@Model.Key" class="product-box">
            <div class="imageWrap">
                @if (Model.HasValue("image"))
                {
                    var mediaId = Model.GetPropertyValue<string>("image");
                    var image = Umbraco.TypedMedia(mediaId);
                    <img style="width:100%;" class="img-responsive" src="@image.GetCropUrl(400, 400)" alt="@Model.Name">
                }
            </div>
    
            <div class="product-info">
                <h3>@Model.Name</h3>
                @if(hasVariants)
                {
                    doesHaveDetachedContents = false;
                    foreach (var productVars in product.ProductVariants)
                    {
    
                        var getProductVariant = mHelper.Query.Product.GetProductVariantByKey(productVars.Key);
    
                        if (getProductVariant.DetachedContents.Any())
                        {
                            foreach (var item in getProductVariant.DetachedContents)
                            {
                                foreach (var dataValues in item.DetachedDataValues)
                                {
                                    if (dataValues.Key == "brief")
                                    {
                                        if(!String.IsNullOrEmpty(dataValues.Value) || dataValues.Value != null)
                                        {
                                            if (lastVariantID.ToLower() != getProductVariant.Key.ToString().ToLower())
                                            {
                                                var productVarBrief = dataValues.Value.Trim().Replace("\"", "");
                                                <div style="display:none;" class="productBriefDescription" id="@getProductVariant.Key">@Html.Raw(productVarBrief)</div>
                                                doesHaveDetachedContents = true;
                                                lastVariantID = getProductVariant.Key.ToString().ToLower();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (!doesHaveDetachedContents)
                    {
                        @Model.GetPropertyValue("brief")
                    }
                }
                else
                {
                    @Model.GetPropertyValue("brief")
                }
    
                @Html.Action("AddProductToBasketForm", "StoreBasket", new { area = "Merchello", model = Model })
            </div>
    </div>
    

    Best regards, Christian

  • David Godfrey 14 posts 83 karma points
    Sep 03, 2017 @ 18:57
    David Godfrey
    0

    Probably not the cause of it but worth checking, are you familiar with the models builder?

    what have you got this set to in umbraco web.config?

    <add key="Umbraco.ModelsBuilder.ModelsMode"
    

    Cheers

  • Christian Hansen 14 posts 85 karma points
    Sep 03, 2017 @ 19:02
    Christian Hansen
    0

    Hi David,

    Thanks for snappy response!

    I am not familiar with the models builder, but it is currently set to:

    <add key="Umbraco.ModelsBuilder.ModelsMode" value="PureLive" />
    
  • David Godfrey 14 posts 83 karma points
    Sep 03, 2017 @ 19:32
    David Godfrey
    0

    I would rule this out as a possible performance killer, has killed some of my sites in the past.

    It something you should read up about if using Umbraco.

    Try setting it to the following:

    <add key="Umbraco.ModelsBuilder.Enable" value="true" />
    <add key="Umbraco.ModelsBuilder.ModelsMode" value="Dll" />
    

    be sure to build your models in the back office once you have made the change.

    Cheers

    David

  • Christian Hansen 14 posts 85 karma points
    Sep 03, 2017 @ 19:37
    Christian Hansen
    0

    I republished cache on all my nodes in Umbraco backoffice. What do you mean with build my models in the back office?

    I get this error now:

    Server Error in '/' Application.
    
    Cannot bind source content type Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedContent to model type Umbraco.Web.PublishedContentModels.FtStore.
    
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    
    Exception Details: Umbraco.Web.Mvc.ModelBindingException: Cannot bind source content type Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedContent to model type Umbraco.Web.PublishedContentModels.FtStore.
    
    Source Error: 
    
    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
    
    Stack Trace: 
    
    
    [ModelBindingException: Cannot bind source content type Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedContent to model type Umbraco.Web.PublishedContentModels.FtStore.]
       Umbraco.Web.Mvc.RenderModelBinder.ThrowModelBindingException(Boolean sourceContent, Boolean modelContent, Type sourceType, Type modelType) +639
       Umbraco.Web.Mvc.RenderModelBinder.BindModel(Object source, Type modelType, CultureInfo culture) +248
       Umbraco.Web.Mvc.UmbracoViewPage`1.SetViewData(ViewDataDictionary viewData) +180
       System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) +99
       System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) +107
       Umbraco.Core.Profiling.ProfilingView.Render(ViewContext viewContext, TextWriter writer) +113
       System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +290
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +56
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +420
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +52
       System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +173
       System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +100
       System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +10
       System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
       System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27
       System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13
       System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
       System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
       System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +38
       System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12
       System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +22
       System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
       System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +28
       System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10
       System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21
       System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +29
       System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
       System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
       System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9986301
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155
    
    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.2103.2
    
  • David Godfrey 14 posts 83 karma points
    Sep 03, 2017 @ 20:03
    David Godfrey
    0

    If you login to the back office and go to the developer tab you should be able to see models builder within the right hand frame. CLick on this and then click the red button titled Generate models.

  • Christian Hansen 14 posts 85 karma points
    Sep 03, 2017 @ 20:27
    Christian Hansen
    0

    Ah right - I did it and now no errors, but sadly no change in regards to loading time on that specific page with all my products on.

  • David Godfrey 14 posts 83 karma points
    Sep 03, 2017 @ 21:07
    David Godfrey
    0

    Have you tried commenting out the individual if statements and for loops to find the offending line of code?

  • David Godfrey 14 posts 83 karma points
    Sep 03, 2017 @ 21:14
    David Godfrey
    0

    I have found using the detachedContent a little problematic, I'm not happy with my solution but plan to rewrite it when I have more time.

    I am using the following at the moment:

     foreach (var option in product.ProductOptions)
                        {
    
    
                            var choices = option.Choices.OrderBy(x => x.SortOrder).Select(choice => new System.Web.Mvc.SelectListItem { Value = choice.Key.ToString(), Text = choice.Name }).ToList();
                            choices.First().Selected = true;
    
    
    
    
                            <br />
                            if (option.Name.ToLower() == "size")
                            {
    
                                var oindex = 0;
                                foreach (var choice in option.Choices)
                                {
    
    
                                    if (@choice.DetachedDataValues.FirstOrDefault().Key == "productImageSelector")
                                    {
    
                                        string str = choice.DetachedDataValues.FirstOrDefault().Value;
    
    
    
                    }
    
              }
    
            }
        }
    
  • Christian Hansen 14 posts 85 karma points
    Sep 04, 2017 @ 18:09
    Christian Hansen
    0

    This is product options you are accessing and not detached content which is what I need that contains a product variants description :)

  • Christian Hansen 14 posts 85 karma points
    Sep 04, 2017 @ 18:08
    Christian Hansen
    0

    Yes I have found the offending line of code as stated in the subject line, but maybe I should of written that in the post.

    This line alone without anything else causes severe loading times: var product = mHelper.Query.Product.GetByKey(Model.Key);

    It does loop through alot of product variants though, but still should not be this slow

  • Christian Hansen 14 posts 85 karma points
    Sep 12, 2017 @ 19:20
    Christian Hansen
    0

    Bump... :(

Please Sign in or register to post replies

Write your reply to:

Draft