Code for updating field taking forever

Posted by Community Admin on 04-Aug-2018 15:02

Code for updating field taking forever

All Replies

Posted by Community Admin on 16-Jul-2014 00:00

I have the following code below that is taking a VERY long time to execute.  I am monitoring the DB and it does appear to be working, however it is taking a long time!  Do you see any issues with the code or a better way to write the code to improve the performance?

DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
            Type accordianPanelType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.AccordianPanels.AccordianPanel");
 
            var panels = dynamicModuleManager.GetDataItems(accordianPanelType).Where(p =>
                p.Status == ContentLifecycleStatus.Live);;
 
            foreach (DynamicContent panel in panels)
            
                foreach (var ac in panel.AvailableCultures)
                
                    if (ac.ToString() != "")
                    
                        System.Threading.Thread.CurrentThread.CurrentUICulture = ac;
                        string tabName = panel.GetString("Title");
                        //Update TabName field
                        panel.SetValue("TabName", tabName);
                        //Save Changes
                        dynamicModuleManager.SaveChanges();
                    
                
            

Posted by Community Admin on 21-Jul-2014 00:00

Hello Jared,

What you could optimize is to call SaveChanges only once after all items have been modified, outside the foreach loops. Basically, this is the slowest operation you are executing. However, on what number of items you are executing this?

Regards,
Nikola Zagorchev
Telerik

 
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed