summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Carver2017-12-01 15:10:06 -0600
committerMark Carver2017-12-01 17:45:20 -0600
commitadd90c92bd4a03ebda34122941ab1e3f64468294 (patch)
treee2e05bdfc48aec8be9f57ae6c88f25531c77ea02
parent85b09470a3b84840638e5706a93d14ca9bdd97f7 (diff)
Issue #2927945 by markcarver: _bootstrap_file_scan_directory unnecessarily calls the DB every time7.x-3.x
-rw-r--r--includes/common.inc30
1 files changed, 17 insertions, 13 deletions
diff --git a/includes/common.inc b/includes/common.inc
index 3835f01..d200052 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -559,20 +559,24 @@ function _bootstrap_get_base_themes($theme_key = NULL, $include_theme_key = FALS
* @see file_scan_directory()
*/
function _bootstrap_file_scan_directory($dir, $mask, array $options = array()) {
- // Retrieve cached data.
- $cid = 'theme_registry:bootstrap:files';
- $files = array();
- if ($cache = cache_get($cid)) {
- $files = $cache->data;
- }
- // Generate a unique hash for all parameters passed as a change in any of
- // them would return different results.
- $hash = drupal_hash_base64(serialize(func_get_args()));
- if (!isset($files[$hash])) {
- $files[$hash] = file_scan_directory($dir, $mask, $options);
- cache_set($cid, $files);
+ $files = &drupal_static(__FUNCTION__, array());
+
+ // Generate a unique cache identifier for all parameters passed as a change
+ // in any of them would return different results.
+ $cid = 'theme_registry:bootstrap:files:' . drupal_hash_base64(serialize(func_get_args()));
+
+ // Load from DB cache or scan filesystem if files are not statically cached.
+ if (!isset($files[$cid])) {
+ if (($cache = cache_get($cid)) && isset($cache->data)) {
+ $files[$cid] = $cache->data;
+ }
+ else {
+ $files[$cid] = file_scan_directory($dir, $mask, $options);
+ cache_set($cid, $files[$cid]);
+ }
}
- return $files[$hash];
+
+ return $files[$cid];
}
/**