Index: views.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views/views.module,v retrieving revision 1.341.2.18 diff -u -p -r1.341.2.18 views.module --- views.module 30 Nov 2010 20:40:25 -0000 1.341.2.18 +++ views.module 17 Dec 2010 06:46:57 -0000 @@ -745,21 +745,33 @@ function views_get_plugin($type, $plugin * A view object or NULL if it is not available. */ function &views_get_default_view($view_name) { - $null = NULL; + $return = NULL; + $cid = "views_default:$view_name"; // Attempt to load individually cached view from cache. views_include('cache'); - $data = views_cache_get("views_default:{$view_name}", TRUE); - if (isset($data->data) && is_object($data->data)) { - return $data->data; + $data = views_cache_get($cid, TRUE); + if ($data) { + $return = $data->data; } - - // Otherwise, allow entire cache to be rebuilt. - $cache = views_discover_default_views(); - if (isset($cache[$view_name])) { - return $cache[$view_name]; + else { + // Otherwise, allow entire cache to be rebuilt. + $cache = views_discover_default_views(); + if (isset($cache[$view_name])) { + views_cache_set($cid, $cache[$view_name], TRUE); + $return = $cache[$view_name]; + } + else { + // There is no default view for this view name. To avoid loading all + // default views into memory when this is the case, which can result in + // an additional 20mb of memory usage when loading a view that only + // exists in the databse, cache the fact that we didn't find a default + // view as well. + views_cache_set($cid, NULL, TRUE); + } } - return $null; + + return $return; } /** @@ -784,13 +796,8 @@ function views_new_view() { * @return An associative array of all known default views. */ function views_discover_default_views() { - static $cache = array(); - - if (empty($cache)) { - views_include('cache'); - $cache = _views_discover_default_views(); - } - return $cache; + views_include('cache'); + return _views_discover_default_views(); } /** Index: includes/cache.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/views/includes/cache.inc,v retrieving revision 1.25.2.4 diff -u -p -r1.25.2.4 cache.inc --- includes/cache.inc 12 Mar 2010 01:51:47 -0000 1.25.2.4 +++ includes/cache.inc 17 Dec 2010 06:46:57 -0000 @@ -100,53 +100,46 @@ function _views_discover_default_views() static $cache = NULL; if (!isset($cache)) { - $index = views_cache_get('views_default_views_index', TRUE); + $list = views_cache_get('views_default_views_list', TRUE); - // Retrieve each cached default view - if (isset($index->data) && is_array($index->data)) { - $cache = array(); - foreach ($index->data as $view_name) { - $data = views_cache_get('views_default:' . $view_name, TRUE); - if (isset($data->data) && is_object($data->data)) { - $cache[$view_name] = $data->data; - } - } + // Check if the cached list exists + if (isset($list->data) && is_array($list->data)) { + $cache = $list->data; + return $cache; } - // If missing index, rebuild the cache - else { - views_include_default_views(); - $cache = array(); - - foreach(module_implements('views_default_views') as $module) { - $results = call_user_func($module . "_views_default_views"); - if (!empty($results) && is_array($results)) { - foreach($results as $name => $view) { - // Only views with a sufficiently high api version are eligible. - if (!empty($view->api_version) && $view->api_version >= 2) { - // Do not cache dead handlers. - $view->destroy(); - if (!isset($cache[$name])) { - $cache[$name] = $view; - } - else { - watchdog('view', "View name '@name' is already taken", array('@name' => $name), WATCHDOG_ERROR); - } + + // If missing data, rebuild the cache + views_include_default_views(); + $cache = array(); + + foreach(module_implements('views_default_views') as $module) { + $results = call_user_func($module . "_views_default_views"); + if (!empty($results) && is_array($results)) { + foreach($results as $name => $view) { + // Only views with a sufficiently high api version are eligible. + if (!empty($view->api_version) && $view->api_version >= 2) { + // Do not cache dead handlers. + $view->destroy(); + if (!isset($cache[$name])) { + $cache[$name] = $view; + } + else { + watchdog('view', "View name '@name' is already taken", array('@name' => $name), WATCHDOG_ERROR); } } } } + } - // Allow modules to modify default views before they are cached. - drupal_alter('views_default_views', $cache); + // Allow modules to modify default views before they are cached. + drupal_alter('views_default_views', $cache); - // Cache the index - $index = array_keys($cache); - views_cache_set('views_default_views_index', $index, TRUE); - - // Cache each view - foreach ($cache as $name => $view) { - views_cache_set('views_default:' . $name, $view, TRUE); - } + // Cache the entire set of views + views_cache_set('views_default_views_list', $cache, TRUE); + + // Cache each view individually. + foreach ($cache as $name => $view) { + views_cache_set('views_default:' . $name, $view, TRUE); } }