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.