The mailings screen is very slow to load when there are many campaigns in the database
Overview
Opening the mailings screen takes a very long time (~30 seconds in my case), and this also happens on other pages.
Using the performance analysis of the browser, I was able to pin it down to a javascript loop that breaks down a list of select options into groups: https://github.com/civicrm/civicrm-core/blob/master/js/Common.js#L440 The wrapAll function loops on each element of the group and insert it into the newly created DOM element, which I imagine triggers internally a analyzeHTML event in the browser.
On the mailings screen, this loop is used by the campaigns search field, I'm guessing this problem was not noticed elsewhere because my organisation has defined many campaigns (~ 2000).
Reproduction steps
- Use a database with many campaigns (e.g. 2000)
- Click on Mailings > Sent and scheduled mailings
- Be patient and notice how the browser is stuck while the page loads
Environment information
Your mileage may vary depending on how fast your computer can redraw repeatedly the page
Comments
I have already prepared a fix for it, will PR