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.
Comment | File | Size | Author |
---|---|---|---|
#1 | 1661578-ctools_export_load_object-queries.patch | 861 bytes | Crell |
Comments
Comment #1
Crell CreditAttribution: Crell commentedNot the most elegant patch attached, but it does the job. There may be a better way, but this works for the moment.
Comment #2
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedI 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.
Comment #3
merlinofchaos CreditAttribution: merlinofchaos commentedSeems like a reasonable optimization. Committed and pushed.