Skip to content
Snippets Groups Projects
Commit 6d83d842 authored by Dmytrii Kaiun's avatar Dmytrii Kaiun Committed by Andrii Chyrskyi
Browse files

Issue #3259745 by tBKoT: Use commen_count property instead of function

parent 1d7163ce
Branches
Tags
1 merge request!91Issue #3259745: Comment count function is too slow
......@@ -109,6 +109,9 @@ function _socialbase_get_join_method_icon($title) {
/**
* Get comment count for a node.
*
* @deprecated
* Use $entity->get(<comment_field_name>)->comment_count instead this function.
*/
function _socialbase_node_get_comment_count(NodeInterface $node) {
$comment_count = &drupal_static(__FUNCTION__ . $node->id());
......
......@@ -70,7 +70,7 @@ class Field extends PreprocessBase {
$node = !empty($attached['#object']) ? $attached['#object'] : NULL;
// Count the amount of comments placed on a Node..
if ($node instanceof Node) {
$comment_count = _socialbase_node_get_comment_count($node);
$comment_count = (int) $node->get($element['#field_name'])->comment_count;
// Add it to the title.
$variables['comment_count'] = $comment_count;
......
......@@ -173,7 +173,7 @@ class Node extends PreprocessBase {
// OPEN or CLOSED we can render icon for
// comment count, and add the comment count to the node.
if ($node->$comment_field_name->status != CommentItemInterface::HIDDEN) {
$comment_count = _socialbase_node_get_comment_count($node);
$comment_count = (int) $node->get($comment_field_name)->comment_count;
$variables['below_content'][$comment_field_name]['#title'] = $comment_count === 0 ? t('Be the first one to comment') : t('Comments');
// If it's closed, we only show the comment section when there are
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment