diff --git a/drupalorg/drupalorg.info b/drupalorg/drupalorg.info index a2084ba..e8890d3 100644 --- a/drupalorg/drupalorg.info +++ b/drupalorg/drupalorg.info @@ -10,5 +10,6 @@ dependencies[] = views_content_cache dependencies[] = features (>=2.x) dependencies[] = drupalorg_git_gateway dependencies[] = drupalorg_versioncontrol +dependencies[] = render_cache_comment scripts[] = js/general.js core = 7.x diff --git a/drupalorg/drupalorg.module b/drupalorg/drupalorg.module index 129ae42..61d1f50 100755 --- a/drupalorg/drupalorg.module +++ b/drupalorg/drupalorg.module @@ -2818,3 +2818,62 @@ function drupalorg_user_update(&$edit, $account, $category) { } } } + +/** + * Implements hook_render_cache_entity_default_cache_info_alter(). + */ +function drupalorg_render_cache_entity_default_cache_info_alter(&$cache_info, $context) { + // Disable entity_view() render caching by default to avoid side effects. + $cache_info['granularity'] = DRUPAL_NO_CACHE; +} + +/** + * Implements hook_render_cache_entity_cache_info_alter(). + */ +function drupalorg_render_cache_entity_cache_info_alter(&$cache_info, $entity, $context) { + // Allow to disable render caching via variable. + if (!variable_get('drupalorg_render_cache_enabled', TRUE)) { + return; + } + + // Always render_to_markup if possible. + // Yes, please save rendered data. + $cache_info['render_cache_render_to_markup'] = TRUE; + + // Check if render caching should be enabled for comments. + if (variable_get('drupalorg_render_cache_comment_enabled', TRUE) + && $context['entity_type'] == 'comment' + && $context['view_mode'] == 'full') { + $cache_info['granularity'] = DRUPAL_CACHE_PER_ROLE; + // Store that this needs special comment processing. + $cache_info['drupalorg_comment_processing'] = TRUE; + } +} + +/** + * Implements hook_render_cache_entity_hash_alter(). + */ +function drupalorg_render_cache_entity_hash_alter(&$hash, $entity, $cache_info, $context) { + if (!empty($cache_info['drupalorg_comment_processing'])) { + // Comment is displaying users, so need to add this to the hash, entity is already added. + $hash['comment_uid'] = $entity->uid; + if (!empty($entity->uid)) { + $hash['comment_uid_modified'] = entity_modified_last_id('user', $entity->uid); + } + + $hash['is_viewer'] = $entity->uid == $GLOBALS['user']->uid; + + $node = node_load($entity->nid); + $hash['is_author'] = $entity->uid == $node->uid; + + $hash['is_new'] = !empty($entity->new); + $hash['first_new'] = !empty($entity->first_new); + + // @todo Maybe disable caching for preview? + $hash['in_preview'] = isset($entity->in_preview); + + // @todo Maybe disable caching for threaded comments? + $hash['divs'] = isset($entity->divs) ? $entity->divs : ''; + $hash['divs_final'] = isset($entity->divs_final) ? $entity->divs_final : ''; + } +}