Skip to content

Commit 9559160

Browse files
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.
1 parent d6c5029 commit 9559160

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

CHANGELOG.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
Drupal 7.33, xxxx-xx-xx (development version)
33
-----------------------
4+
- Added a "block_cache_bypass_node_grants" variable to allow sites which have
5+
node access modules enabled to use the block cache if desired (API addition).
46
- Made image derivative generation HTTP requests return a 404 error (rather
57
than a 500 error) when the source image does not exist.
68
- Fixed a bug which caused user pictures to be removed from the user object

modules/block/block.module

+13-4
Original file line numberDiff line numberDiff line change
@@ -848,10 +848,19 @@ function block_block_list_alter(&$blocks) {
848848
* An array of visible blocks as expected by drupal_render().
849849
*/
850850
function _block_render_blocks($region_blocks) {
851-
// Block caching is not compatible with node access modules. We also
852-
// preserve the submission of forms in blocks, by fetching from cache only
851+
$cacheable = TRUE;
852+
853+
// We preserve the submission of forms in blocks, by fetching from cache only
853854
// if the request method is 'GET' (or 'HEAD').
854-
$cacheable = !count(module_implements('node_grants')) && ($_SERVER['REQUEST_METHOD'] == 'GET' || $_SERVER['REQUEST_METHOD'] == 'HEAD');
855+
if ($_SERVER['REQUEST_METHOD'] != 'GET' && $_SERVER['REQUEST_METHOD'] != 'HEAD') {
856+
$cacheable = FALSE;
857+
}
858+
// Block caching is not usually compatible with node access modules, so by
859+
// default it is disabled when node access modules exist. However, it can be
860+
// allowed by using the variable 'block_cache_bypass_node_grants'.
861+
elseif (!variable_get('block_cache_bypass_node_grants', FALSE) && count(module_implements('node_grants'))) {
862+
$cacheable = FALSE;
863+
}
855864

856865
// Proceed to loop over all blocks in order to compute their respective cache
857866
// identifiers; this allows us to do one single cache_get_multiple() call
@@ -1054,7 +1063,7 @@ function block_menu_delete($menu) {
10541063
* Implements hook_form_FORM_ID_alter().
10551064
*/
10561065
function block_form_system_performance_settings_alter(&$form, &$form_state) {
1057-
$disabled = count(module_implements('node_grants'));
1066+
$disabled = (!variable_get('block_cache_bypass_node_grants', FALSE) && count(module_implements('node_grants')));
10581067
$form['caching']['block_cache'] = array(
10591068
'#type' => 'checkbox',
10601069
'#title' => t('Cache blocks'),

sites/default/default.settings.php

+12
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,18 @@
434434
# $conf['css_gzip_compression'] = FALSE;
435435
# $conf['js_gzip_compression'] = FALSE;
436436

437+
/**
438+
* Block caching:
439+
*
440+
* Block caching may not be compatible with node access modules depending on
441+
* how the original block cache policy is defined by the module that provides
442+
* the block. By default, Drupal therefore disables block caching when one or
443+
* more modules implement hook_node_grants(). If you consider block caching to
444+
* be safe on your site and want to bypass this restriction, uncomment the line
445+
* below.
446+
*/
447+
# $conf['block_cache_bypass_node_grants'] = TRUE;
448+
437449
/**
438450
* String overrides:
439451
*

0 commit comments

Comments
 (0)