Products Performance Issue

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
1 ano atrás
Hi, We are facing a performance issue. The problem starts when we generate the products list with its description and picture.
We are noticing that the execution of the method ProductModelFactory.PrepareProductOverviewPictureModel() is taking a lot of time. As we saw, this method makes some validations before to retorns the object PicterModel, for example, its checks if the picture exists or not inside the server.
This validations are taking a lot of time so the loading time is very long.

Are this validation mandatory?
Does it exist any way to by pass this validations?
If we create a new method with this responsability. Is there any matter that we have to considerate?

The version of nopCommerce we use is 4.3

This es the method:

/// <summary>
/// Prepare the product overview picture model
/// </summary>
/// <param name="product">Product</param>
/// <param name="productThumbPictureSize">Product thumb picture size (longest side); pass null to use the default value of media settings</param>
/// <returns>Picture model</returns>
protected virtual PictureModel PrepareProductOverviewPictureModel(Product product, int? productThumbPictureSize = null)
{
  if (product == null)
    throw new ArgumentNullException(nameof(product));

   var productName = _localizationService.GetLocalized(product, x => x.Name);
  //If a size has been set in the view, we use it in priority
  var pictureSize = productThumbPictureSize ?? _mediaSettings.ProductThumbPictureSize;

   //prepare picture model
  var cacheKey = _cacheKeyService.PrepareKeyForDefaultCache(NopModelCacheDefaults.ProductDefaultPictureModelKey,
    product, pictureSize, true, _workContext.WorkingLanguage, _webHelper.IsCurrentConnectionSecured(),
    _storeContext.CurrentStore);

   var defaultPictureModel = _staticCacheManager.Get(cacheKey, () =>
  {
    var picture = _pictureService.GetPicturesByProductId(product.Id, 1).FirstOrDefault();
    var pictureModel = new PictureModel
    {
      ImageUrl = _pictureService.GetPictureUrl(ref picture, pictureSize),
      FullSizeImageUrl = _pictureService.GetPictureUrl(ref picture),
      //"title" attribute
      Title = (picture != null && !string.IsNullOrEmpty(picture.TitleAttribute))
        ? picture.TitleAttribute
        : string.Format(_localizationService.GetResource("Media.Product.ImageLinkTitleFormat"),
          productName),
      //"alt" attribute
      AlternateText = (picture != null && !string.IsNullOrEmpty(picture.AltAttribute))
        ? picture.AltAttribute
        : string.Format(_localizationService.GetResource("Media.Product.ImageAlternateTextFormat"),
          productName)
    };

     return pictureModel;
  });

   return defaultPictureModel;
}


Thanks.
1 ano atrás
It's not clear to me what "validations" you are referring to.
If a picture thumb does not exist, it needs to be generated.
Are your pictures stored in the DB or in file system?

You really need to "profile" to determine what the problem is (e.g., SQL access, vs web server / file system).
1 ano atrás
Hi. Thank you for answering so quickly.

The pictures are uploaded when de product is created, and the image is saved in the file system. In this process nopCommerce create and assing and URL to this image.
Then, when the product list its created, the system use the method that I mentioned before to create the model witch has all information for this image (name, description, url, etc.).
The problem is that this method take a lot of time to do that.

Thanks
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.