From 9559160204f1c4e72e145cf95d61bf61e4bd1fcf Mon Sep 17 00:00:00 2001 From: David Rothstein Date: Tue, 4 Nov 2014 20:07:30 -0500 Subject: Issue #1930960 by pounard, iamEAP, pjcdawkins, msonnabaum, David_Rothstein: Fixed Block caching disable hardcoded on sites with hook_node_grant() causes serious performance troubles when not necessary. --- modules/block/block.module | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'modules/block') diff --git a/modules/block/block.module b/modules/block/block.module index 2977ca88f..b6a733267 100644 --- a/modules/block/block.module +++ b/modules/block/block.module @@ -848,10 +848,19 @@ 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 + $cacheable = TRUE; + + // We 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'); + if ($_SERVER['REQUEST_METHOD'] != 'GET' && $_SERVER['REQUEST_METHOD'] != 'HEAD') { + $cacheable = FALSE; + } + // Block caching is not usually compatible with node access modules, so by + // default it is disabled when node access modules exist. However, it can be + // allowed by using the variable 'block_cache_bypass_node_grants'. + elseif (!variable_get('block_cache_bypass_node_grants', FALSE) && count(module_implements('node_grants'))) { + $cacheable = FALSE; + } // Proceed to loop over all blocks in order to compute their respective cache // identifiers; this allows us to do one single cache_get_multiple() call @@ -1054,7 +1063,7 @@ function block_menu_delete($menu) { * Implements hook_form_FORM_ID_alter(). */ function block_form_system_performance_settings_alter(&$form, &$form_state) { - $disabled = count(module_implements('node_grants')); + $disabled = (!variable_get('block_cache_bypass_node_grants', FALSE) && count(module_implements('node_grants'))); $form['caching']['block_cache'] = array( '#type' => 'checkbox', '#title' => t('Cache blocks'), -- cgit v1.2.3