commit f321a46bee41aceb319af7e2772997f1ff17f225
Author: Damien Tournoud <damien@commerceguys.com>
Date:   Tue Sep 21 19:46:45 2010 -0400

    #918808: delay the rendering of blocks to enable smart cache strategies.

diff --git a/modules/block/block.module b/modules/block/block.module
index f701482..f3d73d6 100644
--- a/modules/block/block.module
+++ b/modules/block/block.module
@@ -333,8 +333,11 @@ function _block_get_renderable_array($list = array()) {
   $weight = 0;
   $build = array();
   foreach ($list as $key => $block) {
-    $build[$key] = $block->content;
-    unset($block->content);
+    $build[$key] = array(
+      '#pre_render' => array('_block_pre_render_block'),
+      '#block' => $block,
+      '#weight' => ++$weight,
+    );
 
     // Add contextual links for this block; skip the main content block, since
     // contextual links are basically output as tabs/local tasks already. Also
@@ -344,12 +347,6 @@ function _block_get_renderable_array($list = array()) {
     if ($key != 'system_main' && $key != 'system_help') {
       $build[$key]['#contextual_links']['block'] = array('admin/structure/block/manage', array($block->module, $block->delta));
     }
-
-    $build[$key] += array(
-      '#block' => $block,
-      '#weight' => ++$weight,
-    );
-    $build[$key]['#theme_wrappers'][] ='block';
   }
   $build['#sorted'] = TRUE;
   return $build;
@@ -647,9 +644,6 @@ function block_list($region) {
   if (!isset($blocks[$region])) {
     $blocks[$region] = array();
   }
-  else {
-    $blocks[$region] = _block_render_blocks($blocks[$region]);
-  }
 
   return $blocks[$region];
 }
@@ -795,21 +789,16 @@ function block_block_list_alter(&$blocks) {
 }
 
 /**
- * Render the content and subject for a set of blocks.
- *
- * @param $region_blocks
- *   An array of block objects such as returned for one region by _block_load_blocks().
+ * Pre-render fucntion: render the content and subject for a block.
  *
- * @return
- *   An array of visible blocks as expected by drupal_render().
+ * @param $element
+ *   A renderable array.
  */
-function _block_render_blocks($region_blocks) {
-  foreach ($region_blocks as $key => $block) {
+function _block_pre_render_block($element) {
+  $block = $element['#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. Block caching is not compatible
       // with node_access modules. We also preserve the submission of forms in
       // blocks, by fetching from cache only if the request method is 'GET'
@@ -848,11 +837,16 @@ function _block_render_blocks($region_blocks) {
         if (!isset($block->subject)) {
           $block->subject = '';
         }
-        $region_blocks["{$block->module}_{$block->delta}"] = $block;
-      }
+
+      // Replace the stub block element with the full renderable array
+      // that we have now generated.
+      $element = $block->content;
+      unset($block->content);
+      $element['#block'] = $block;
+      $element['#theme_wrappers'][] = 'block';
     }
   }
-  return $region_blocks;
+  return $element;
 }
 
 /**
diff --git a/modules/dashboard/dashboard.module b/modules/dashboard/dashboard.module
index fad6a9e..54c3b41 100644
--- a/modules/dashboard/dashboard.module
+++ b/modules/dashboard/dashboard.module
@@ -490,8 +490,7 @@ function dashboard_show_block_content($module, $delta) {
     ->fetchObject();
   $block_object->enabled = $block_object->page_match = TRUE;
   $blocks[$module . "_" . $delta] = $block_object;
-  $block_content = _block_render_blocks($blocks);
-  $build = _block_get_renderable_array($block_content);
+  $build = _block_get_renderable_array($blocks);
   $rendered_block = drupal_render($build);
   print $rendered_block;
   drupal_exit();
