From df911f3f5081b258eda937c4791eb854fe2720be Mon Sep 17 00:00:00 2001 From: webchick Date: Thu, 1 Mar 2012 21:20:12 -0800 Subject: Issue #917490 by pounard, msonnabaum: Performance patch for block_list() (D6) and _block_render_blocks() (D7) functions. --- modules/block/block.module | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'modules/block') diff --git a/modules/block/block.module b/modules/block/block.module index 24319089e..94dee69c6 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -836,17 +836,18 @@ function block_block_list_alter(&$blocks) { * An array of visible blocks as expected by drupal_render(). */ function _block_render_blocks($region_blocks) { + // Block caching is not compatible with node access modules. We also + // preserve the submission of forms in blocks, by fetching from cache only + // if the request method is 'GET' (or 'HEAD'). + $cacheable = !count(module_implements('node_grants')) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'HEAD'); foreach ($region_blocks as $key => $block) { // Render the block content if it has not been created already. if (!isset($block->content)) { // Erase the block from the static array - we'll put it back if it has // content. unset($region_blocks[$key]); - // Try fetching the block from cache. Block caching is not compatible - // with node_access modules. We also preserve the submission of forms in - // blocks, by fetching from cache only if the request method is 'GET' - // (or 'HEAD'). - if (!count(module_implements('node_grants')) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'HEAD') && ($cid = _block_get_cache_id($block)) && ($cache = cache_get($cid, 'cache_block'))) { + // Try fetching the block from cache. + if ($cacheable && ($cid = _block_get_cache_id($block)) && ($cache = cache_get($cid, 'cache_block'))) { $array = $cache->data; } else { -- cgit v1.2.3