More in this section

Forums / Developing with Sitefinity / Code for updating field taking forever

Code for updating field taking forever

2 posts, 0 answered
  1. Jared
    Jared avatar
    122 posts
    04 Apr 2013
    16 Jul 2014
    Link to this post

    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

  2. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    19 Apr 2017
    21 Jul 2014
    Link to this post
    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?

    Nikola Zagorchev
    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
2 posts, 0 answered