Increase performance in addloacles

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
7 years ago
I have a site where two language is available.

In admin panel product controller edit action result
this snippet code  
AddLocales(_languageService, model.Locales, (locale, languageId) =>
                {
                    locale.Name = product.GetLocalized(x => x.Name, languageId, false, false);
                    locale.ShortDescription = product.GetLocalized(x => x.ShortDescription, languageId, false, false);
                    locale.FullDescription = product.GetLocalized(x => x.FullDescription, languageId, false, false);
                    locale.MetaKeywords = product.GetLocalized(x => x.MetaKeywords, languageId, false, false);
                    locale.MetaDescription = product.GetLocalized(x => x.MetaDescription, languageId, false, false);
                    locale.MetaTitle = product.GetLocalized(x => x.MetaTitle, languageId, false, false);
                    locale.SeName = product.GetSeName(languageId, false, false);
                });

take almost 6 seconds.
My code in edit function

public ActionResult Edit(int id)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageProducts))
                return AccessDeniedView();

            var product = _productService.GetProductById(id);
            if (product == null || product.Deleted)
                //No product found with the specified id
                return RedirectToAction("List");

            //a vendor should have access only to his products
            if (_workContext.CurrentVendor != null && product.VendorId != _workContext.CurrentVendor.Id)
                return RedirectToAction("List");

            var model = product.ToModel();
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            PrepareProductModel(model, product, false, false);
            stopwatch.Stop();
            Debug.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);
            stopwatch.Start();
            AddLocales(_languageService, model.Locales, (locale, languageId) =>
                {
                    locale.Name = product.GetLocalized(x => x.Name, languageId, false, false);
                    locale.ShortDescription = product.GetLocalized(x => x.ShortDescription, languageId, false, false);
                    locale.FullDescription = product.GetLocalized(x => x.FullDescription, languageId, false, false);
                    locale.MetaKeywords = product.GetLocalized(x => x.MetaKeywords, languageId, false, false);
                    locale.MetaDescription = product.GetLocalized(x => x.MetaDescription, languageId, false, false);
                    locale.MetaTitle = product.GetLocalized(x => x.MetaTitle, languageId, false, false);
                    locale.SeName = product.GetSeName(languageId, false, false);
                });
            stopwatch.Stop();
            Debug.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);
            stopwatch.Start();
            PrepareAclModel(model, product, false);
            stopwatch.Stop();
            Debug.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);
            stopwatch.Start();
            PrepareStoresMappingModel(model, product, false);
            stopwatch.Stop();
            Debug.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);
            stopwatch.Start();
            PrepareAddProductPictureModel(model);
            stopwatch.Stop();
            Debug.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);
            stopwatch.Start();
            PrepareStickerTypeModel(model);
            stopwatch.Stop();
            Debug.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);
            stopwatch.Start();
            PrepareStickerColorModel(model);
            stopwatch.Stop();
            Debug.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);
            stopwatch.Start();
            PrepareStickerShapeModel(model);
            stopwatch.Stop();
            Debug.WriteLine("Time elapsed: {0}", stopwatch.Elapsed);
            return View(model);
        }


time taking here
Time elapsed: 00:00:00.8479027
Time elapsed: 00:00:06.1528029
Time elapsed: 00:00:06.1921305
Time elapsed: 00:00:06.2090919
Time elapsed: 00:00:06.2426028
Time elapsed: 00:00:06.2619983
Time elapsed: 00:00:06.2859464
Time elapsed: 00:00:06.3033478


Is there any way to increase performance in addlocales function?
7 years ago
Does it happen only for the first time when you load the page? Is it still slow when you refresh the page (without any save)?
7 years ago
It take that much time when I click on save-continue button. If I reload it don't take that much time.
7 years ago
I presume you have a lot of localized fields. Go to admin area > settings > general settings. Is "Load all localized properties on startup" enabled? If yes, disable it and try one more time
7 years ago
How it help to increase performance? Can you explain or can you give me any hint where I check this code ?
7 years ago
So do you have "Load all localized properties on startup" enabled? How many records do you have in "LocalizedProperty" table?

P.S. Please see "SaveLocalizedValue" and "GetLocalizedProperties" methods of \Nop.Services\Localization\LocalizedEntityService.cs
7 years ago
It reduces time huge. Total data is 150546.
Now the value is
Time elapsed: 00:00:00.3407627
Time elapsed: 00:00:00.6497909
Time elapsed: 00:00:00.6672404
Time elapsed: 00:00:00.6673262
Time elapsed: 00:00:00.6805984
Time elapsed: 00:00:00.6974317
Time elapsed: 00:00:00.7121063
Time elapsed: 00:00:00.7269525
7 years ago
I have a suggestion I don't know it is good or bad
public virtual void UpdateLocalizedProperty(LocalizedProperty localizedProperty)
        {
            if (localizedProperty == null)
                throw new ArgumentNullException("localizedProperty");

            _localizedPropertyRepository.Update(localizedProperty);

            //cache
            _cacheManager.RemoveByPattern(LOCALIZEDPROPERTY_PATTERN_KEY);
        }

I think it is not good for updating a single data we remove whole cache data. Instead we can update single cache property here.
7 years ago
anik1991 wrote:
I think it is not good for updating a single data we remove whole cache data. Instead we can update single cache property here.

Thanks! This work item already exists
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.