Skip to content
Snippets Groups Projects
Commit 43c8918f authored by David Rothstein's avatar David Rothstein
Browse files

Issue #1956914 by chaby, pounard: Use a single cache_get_multiple() call per...

Issue #1956914 by chaby, pounard: Use a single cache_get_multiple() call per region instead of a cache_get() per block in _block_render_blocks().
parent 0758630a
No related branches found
No related tags found
No related merge requests found
......@@ -840,15 +840,37 @@ 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 a 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();
if ($cacheable) {
$cids = array();
foreach ($region_blocks as $key => $block) {
if (!isset($block->content)) {
if (($cid = _block_get_cache_id($block))) {
$cids[] = $cid;
}
}
}
if ($cids) {
$cached_blocks = cache_get_multiple($cids, '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;
// Try fetching the block from the previously loaded cache entries.
if (($cid = _block_get_cache_id($block)) && isset($cached_blocks[$cid])) {
$array = $cached_blocks[$cid]->data;
}
else {
$array = module_invoke($block->module, 'block_view', $block->delta);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment