Looking through the devel query logs on a site of mine, I see the following query getting run nearly 2 dozen times:

SELECT 1 FROM page_manager_pages LIMIT 0, 1

It's also always called from ctools_export_load_object().

Poking around a bit, I found the function begins this way:

function ctools_export_load_object($table, $type = 'all', $args = array()) {
  $cache = &drupal_static(__FUNCTION__);
  $cached_database = &drupal_static('ctools_export_load_object_all');

  $schema = ctools_export_get_schema($table);
  if (empty($schema) || !db_table_exists($table)) {
    return array();

db_table_exists() works by issuing an uncached query against the specified table, and getting back either a 1 (true) or an exception (false). That means every single call to this function will generate another repeated SQL query.

IMO, that information should not be static-cached in the DB layer itself. Rather, ctools_export_load_object() should be caching that information in some way.

#1 1661578-ctools_export_load_object-queries.patch861 bytesCrell
PASSED: [[SimpleTest]]: [MySQL] 24 pass(es). View


Crell’s picture

Status: Active » Needs review
861 bytes
PASSED: [[SimpleTest]]: [MySQL] 24 pass(es). View

Not the most elegant patch attached, but it does the job. There may be a better way, but this works for the moment.

SocialNicheGuru’s picture

I have noticed multiple calls to ctools_export_load_object when I enabled devel.

I will try this patch to see if the time to execute the function decreases.

merlinofchaos’s picture

Status: Needs review » Fixed

Seems like a reasonable optimization. Committed and pushed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.