diff --git modules/rdf/rdf.module modules/rdf/rdf.module index 1c231f3..157af4c 100644 --- modules/rdf/rdf.module +++ modules/rdf/rdf.module @@ -523,17 +523,45 @@ function rdf_preprocess_username(&$variables) { */ function rdf_preprocess_comment(&$variables) { $comment = $variables['comment']; + + // Centralizes and caches variables which are expensive to generate. + static $cdata; + if (empty($cdata)) { + // Attempt to load data for the comments to be displayed from cache. + $node = node_load($comment->nid); + $mode = variable_get('comment_default_mode_' . $node->type, COMMENT_MODE_THREADED); + $comments_per_page = variable_get('comment_default_per_page_' . $node->type, 50); + if ($cids = comment_get_thread($node, $mode, $comments_per_page)) { + foreach ($cids as $k => $cid) { + $cids[$k] = 'comment:' . $cid; + } + $cdata = cache_get_multiple($cids, 'cache'); + } + } + + $cid = 'comment:' . $comment->cid; + if (!empty($cdata[$cid])) { + $v = $cdata[$cid]->data; + } + else { + $v['url1'] = url('comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid)); + $v['rdfa1'] = rdf_rdfa_attributes($comment->rdf_mapping['created'], $comment->created); + $v['url2'] = url('node/' . $comment->nid); + $v['url3'] = url('comment/' . $comment->pid, array('fragment' => 'comment-' . $comment->pid)); + cache_set($cid, $v); + } + if (!empty($comment->rdf_mapping['rdftype'])) { // Adds RDFa markup to the comment container. The about attribute specifies // the URI of the resource described within the HTML element, while the // typeof attribute indicates its RDF type (e.g. sioc:Post, etc.). - $variables['attributes_array']['about'] = url('comment/' . $comment->cid, array('fragment' => 'comment-' . $comment->cid)); + $variables['attributes_array']['about'] = $v['url1']; $variables['attributes_array']['typeof'] = $comment->rdf_mapping['rdftype']; } // Adds RDFa markup for the date of the comment. if (!empty($comment->rdf_mapping['created'])) { - $date_attributes_array = rdf_rdfa_attributes($comment->rdf_mapping['created'], $comment->created); + $date_attributes_array = $v['rdfa1']; $variables['rdf_template_variable_attributes_array']['created'] = $date_attributes_array; } // Adds RDFa markup for the relation between the comment and its author. @@ -561,13 +589,13 @@ function rdf_preprocess_comment(&$variables) { if (!empty($comment->rdf_mapping['pid'])) { // Relation to parent node. $parent_node_attributes['rel'] = $comment->rdf_mapping['pid']['predicates']; - $parent_node_attributes['resource'] = url('node/' . $comment->nid); + $parent_node_attributes['resource'] = $v['url2']; $variables['rdf_metadata_attributes_array'][] = $parent_node_attributes; // Relation to parent comment if it exists. if ($comment->pid != 0) { $parent_comment_attributes['rel'] = $comment->rdf_mapping['pid']['predicates']; - $parent_comment_attributes['resource'] = url('comment/' . $comment->pid, array('fragment' => 'comment-' . $comment->pid)); + $parent_comment_attributes['resource'] = $v['url3']; $variables['rdf_metadata_attributes_array'][] = $parent_comment_attributes; } }