summaryrefslogtreecommitdiff
path: root/modules/block
diff options
context:
space:
mode:
authorDavid Rothstein <drothstein@gmail.com>2013-08-05 21:42:42 -0400
committerDavid Rothstein <drothstein@gmail.com>2013-08-05 21:42:42 -0400
commit19dc0fc8cdb97729a14a61e6d83568f05c3802c6 (patch)
tree51a50f94b0e93df01bfea43fb6acd050f09875ef /modules/block
parentcadd940917efc18715172ee29b9c8128affcddaa (diff)
downloadbrdo-19dc0fc8cdb97729a14a61e6d83568f05c3802c6.tar.gz
brdo-19dc0fc8cdb97729a14a61e6d83568f05c3802c6.tar.bz2
Issue #1956914 by pounard, David_Rothstein, chaby: Use a single cache_get_multiple() call per region instead of a cache_get() per block in _block_render_blocks().
Diffstat (limited to 'modules/block')
-rw-r--r--modules/block/block.module33
1 files changed, 30 insertions, 3 deletions
diff --git a/modules/block/block.module b/modules/block/block.module
index ff77d9ec3..3a988de2c 100644
--- a/modules/block/block.module
+++ b/modules/block/block.module
@@ -840,15 +840,42 @@ function _block_render_blocks($region_blocks) {
// 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');
+
+ // 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
+ // instead of doing one cache_get() call per block.
+ $cached_blocks = array();
+ $cids = array();
+
+ if ($cacheable) {
+ foreach ($region_blocks as $key => $block) {
+ if (!isset($block->content)) {
+ if (($cid = _block_get_cache_id($block))) {
+ $cids[$key] = $cid;
+ }
+ }
+ }
+
+ if ($cids) {
+ // We cannot pass $cids in directly because cache_get_multiple() will
+ // modify it, and we need to use it later on in this function.
+ $cid_values = array_values($cids);
+ $cached_blocks = cache_get_multiple($cid_values, 'cache_block');
+ }
+ }
+
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.
- if ($cacheable && ($cid = _block_get_cache_id($block)) && ($cache = cache_get($cid, 'cache_block'))) {
- $array = $cache->data;
+
+ $cid = empty($cids[$key]) ? NULL : $cids[$key];
+
+ // Try fetching the block from the previously loaded cache entries.
+ if (isset($cached_blocks[$cid])) {
+ $array = $cached_blocks[$cid]->data;
}
else {
$array = module_invoke($block->module, 'block_view', $block->delta);