Slow loading module list page

Number one:

On the module list page count of SQL queries more than 1000.

In sources I find this:

  drupal_rebuild_theme_registry();
  node_types_rebuild();
  menu_rebuild();
  cache_clear_all('schema', 'cache');

I suggest to add check:

if ($form_state['post']) {
  drupal_rebuild_theme_registry();
  node_types_rebuild();
  menu_rebuild();
  cache_clear_all('schema', 'cache');
}

After this, queries count bring down to 100+

Number two:

file menu.inc

    foreach ($menu_links as $item) {
      $existing_item = db_fetch_array(db_query("SELECT mlid, menu_name, plid, customized, has_children, updated FROM {menu_links} WHERE link_path = '%s' AND module = '%s'", $item['link_path'], 'system'));
      if ($existing_item) {
        $item['mlid'] = $existing_item['mlid'];
        // A change in hook_menu may move the link to a different menu
        if (empty($item['menu_name']) || ($item['menu_name'] == $existing_item['menu_name'])) {
          $item['menu_name'] = $existing_item['menu_name'];
          $item['plid'] = $existing_item['plid'];
        }
        $item['has_children'] = $existing_item['has_children'];
        $item['updated'] = $existing_item['updated'];
      }

There we have db_fetch_array(db_query.. executed on each iteration of `foreach`. Why not make like this:

    $paths = db_query("SELECT mlid, menu_name, plid, customized, has_children, updated, link_path FROM {menu_links} WHERE link_path IN ('" . implode('\',\'',array_keys($menu_links)) . "') AND module = 'system'");
    while ( $item = db_fetch_array($paths) )
        $m_links[$item['link_path']] = $item;

    foreach ($menu_links as $item) {
      if ($m_links[$item['link_path']]) {
        $existing_item = $m_links[$item['link_path']];
        $item['mlid'] = $existing_item['mlid'];
...

I guess, my variant little faster, eh? (-:

Don't like hacks, but I like

kees@qrios - March 6, 2009 - 19:49

Don't like hacks, but I like this for development sites, this really speeds up loading the module page and caches are cleared/registries rebuilt anyway upon saving.
Good enough for me.

Related: http://drupal.org/node/311626

I have no idea what I just

freixas - March 25, 2009 - 17:16

I have no idea what I just did to my system, but by making change #1 (in system.admin.inc), The modules page load time dropped from 112 seconds to 14 seconds. The number of queries dropped from about 4,000 to 179.

First solution works! Cut it down 90%

lrobeson - April 13, 2009 - 15:53

I tried your first solution and my Module List page went from 4964 queries in 62830.76 milliseconds to 288 queries in 6566.13 milliseconds. Thank you! I'm new to Drupal so I'm not sure what that just did, but it worked perfectly!

I added it too and it seems to have had a postive effect

activelyOUT - May 4, 2009 - 22:23

working on my site has been hard because of the slow speed. so i have been scavenging drupal.org for a way to make things quicker.

I deleted all my content and yet the site is still slow. I have lots of modules but on my dev system which is still faster.

I would start from my dev system except I don't know how to import my taxonomy terms with the exact same IDs so when I import from my production site everything will be in symc.

Whats the difference between

kees@qrios - May 5, 2009 - 17:47

Whats the difference between "my site" and "my dev system"? Different OS? HW? SW? Drupal version? Different modules? config?

Slow loading module list page - hack #2

RedStaff - June 1, 2009 - 17:33

Can you please tell me what go where?

I tried to substitue the "foreach ($menu_links as $item)" block with

$paths = db_query("SELECT mlid, menu_name, plid, customized, has_children, updated, link_path FROM {menu_links} WHERE link_path IN ('" . implode('\',\'',array_keys($menu_links)) . "') AND module = 'system'");
while ( $item = db_fetch_array($paths) )
$m_links[$item['link_path']] = $item;

foreach ($menu_links as $item) {
if ($m_links[$item['link_path']]) {
$existing_item = $m_links[$item['link_path']];
$item['mlid'] = $existing_item['mlid'];

but I keep on getting parsing errors.

Thank you very much.

 
 

Drupal is a registered trademark of Dries Buytaert.