summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rothstein <drothstein@gmail.com>2014-11-04 20:07:30 -0500
committerDavid Rothstein <drothstein@gmail.com>2014-11-04 20:07:30 -0500
commit9559160204f1c4e72e145cf95d61bf61e4bd1fcf (patch)
tree7d90d37162f5694ea079122846bf4ed2ffb4b50b
parentd6c502926e1286e22771c58e01db386ba80d6480 (diff)
downloadbrdo-9559160204f1c4e72e145cf95d61bf61e4bd1fcf.tar.gz
brdo-9559160204f1c4e72e145cf95d61bf61e4bd1fcf.tar.bz2
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.
-rw-r--r--CHANGELOG.txt2
-rw-r--r--modules/block/block.module17
-rw-r--r--sites/default/default.settings.php12
3 files changed, 27 insertions, 4 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 427e20b5b..6192f3989 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,6 +1,8 @@
Drupal 7.33, xxxx-xx-xx (development version)
-----------------------
+- Added a "block_cache_bypass_node_grants" variable to allow sites which have
+ node access modules enabled to use the block cache if desired (API addition).
- Made image derivative generation HTTP requests return a 404 error (rather
than a 500 error) when the source image does not exist.
- Fixed a bug which caused user pictures to be removed from the user object
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'),
diff --git a/sites/default/default.settings.php b/sites/default/default.settings.php
index fc1240d0d..449f18867 100644
--- a/sites/default/default.settings.php
+++ b/sites/default/default.settings.php
@@ -435,6 +435,18 @@ ini_set('session.cookie_lifetime', 2000000);
# $conf['js_gzip_compression'] = FALSE;
/**
+ * Block caching:
+ *
+ * Block caching may not be compatible with node access modules depending on
+ * how the original block cache policy is defined by the module that provides
+ * the block. By default, Drupal therefore disables block caching when one or
+ * more modules implement hook_node_grants(). If you consider block caching to
+ * be safe on your site and want to bypass this restriction, uncomment the line
+ * below.
+ */
+# $conf['block_cache_bypass_node_grants'] = TRUE;
+
+/**
* String overrides:
*
* To override specific strings on your site with or without enabling the Locale