Skip to content

Commit

Permalink
perf(comments): river comments are no longer full views
Browse files Browse the repository at this point in the history
  • Loading branch information
jeabakker committed Aug 6, 2024
1 parent 45c1fc2 commit ded1060
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 70 deletions.
22 changes: 8 additions & 14 deletions views/default/elements/components/comments.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,18 @@
}

.elgg-item-object-comment {

padding: 0;
article {
padding: 1rem;
border-style: solid;
border-color: $(border-color-soft);
border-width: 1px;
}

> .elgg-listing-full {
margin: 0;

> .elgg-listing-full-header {
.elgg-listing-full-header {
margin: 0;

padding: 1rem;
border-style: solid;
border-color: $(border-color-soft);
border-width: 1px;

.elgg-listing-summary-content {
margin: 0;
}
}

> .elgg-listing-full-responses {
padding: 0 0 0 2rem;

Expand Down
82 changes: 37 additions & 45 deletions views/default/object/comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,59 +24,51 @@
elgg_import_esm('elgg/comments');
}

$params = [
'icon_entity' => $commenter,
'time_href' => $comment->getURL(),
'access' => false,
'title' => false,
'tag_name' => 'article',
'imprint' => elgg_extract('imprint', $vars, []),
'class' => elgg_extract_class($vars),
];
$params = $params + $vars;

if ($comment->isCreatedByContentOwner()) {
$params['class'][] = 'elgg-comment-by-owner';

$params['imprint'][] = [
'icon_name' => 'user-edit',
'content' => elgg_echo('generic_comment:by_owner'),
];
}

if ($full_view) {
if (elgg_extract('show_excerpt', $vars)) {
$body = elgg_view('output/longtext', [
'value' => elgg_get_excerpt((string) $comment->description),
]);
} else {
$body = elgg_view('output/longtext', [
'value' => $comment->description,
]);
$params['show_summary'] = true;

if (elgg_extract('show_add_form', $vars, true) && $comment->canComment()) {
$body .= elgg_view('output/url', [
'text' => elgg_echo('generic_comments:add'),
'href' => "#elgg-form-comment-save-{$comment->guid}",
'data-load-comment' => $comment->guid,
'class' => ['elgg-subtext', 'elgg-toggle-comment'],
]);
}
$body = elgg_view('output/longtext', [
'value' => $comment->description,
]);

if (elgg_extract('show_add_form', $vars, true) && $comment->canComment()) {
$body .= elgg_view('output/url', [
'text' => elgg_echo('generic_comments:add'),
'href' => "#elgg-form-comment-save-{$comment->guid}",
'data-load-comment' => $comment->guid,
'class' => ['elgg-subtext', 'elgg-toggle-comment'],
]);
}

$params = [
'icon_entity' => $commenter,
'time_href' => $comment->getURL(),
'access' => false,
'title' => false,
'show_summary' => true,
'tag_name' => 'article',
'content' => $body,
'imprint' => elgg_extract('imprint', $vars, []),
'class' => elgg_extract_class($vars),
];
$params = $params + $vars;

$params['content'] = $body;

if (!empty(elgg()->thread_preloader->getChildren($comment->guid))) {
$params['class'][] = 'with-children';
}

if ($comment->isCreatedByContentOwner()) {
$params['class'][] = 'elgg-comment-by-owner';

$params['imprint'][] = [
'icon_name' => 'user-edit',
'content' => elgg_echo('generic_comment:by_owner'),
];
}

echo elgg_view('object/elements/full', $params);
} else {
$friendlytime = elgg_view_friendly_time($comment->time_created);
$excerpt = elgg_get_excerpt((string) $comment->description, 80);
$posted = elgg_echo('generic_comment:on', [elgg_view_entity_url($commenter), elgg_view_entity_url($entity)]);

$body = elgg_format_element('span', ['class' => 'elgg-subtext'], "{$posted} ({$friendlytime}): {$excerpt}");

echo elgg_view_image_block(elgg_view_entity_icon($commenter, 'small'), $body);
$params['content'] = elgg_get_excerpt((string) $comment->description);

echo elgg_view('object/elements/summary', $params);
}
25 changes: 25 additions & 0 deletions views/default/object/comment/sidebar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
/**
* Show a comment in the sidebar
*
* @uses $vars['entity'] the comment to show
*/

$comment = elgg_extract('entity', $vars);
if (!$comment instanceof \ElggComment) {
return;
}

$entity = $comment->getContainerEntity();
$commenter = $comment->getOwnerEntity();
if (!$entity instanceof \ElggEntity || !$commenter instanceof \ElggEntity) {
return;
}

$friendlytime = elgg_view_friendly_time($comment->time_created);
$excerpt = elgg_get_excerpt((string) $comment->description, 80);
$posted = elgg_echo('generic_comment:on', [elgg_view_entity_url($commenter), elgg_view_entity_url($entity)]);

$body = elgg_format_element('span', ['class' => 'elgg-subtext'], "{$posted} ({$friendlytime}): {$excerpt}");

echo elgg_view_image_block(elgg_view_entity_icon($commenter, 'small'), $body);
4 changes: 2 additions & 2 deletions views/default/page/elements/comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@
'container_guid' => $entity->guid,
'metadata_name_value_pairs' => ['level' => 1],
'wheres' => [
function(QueryBuilder $qb) use ($show_guid, $latest_first) {
function(QueryBuilder $qb, $main_alias) use ($show_guid, $latest_first) {
$operator = $latest_first ? '>' : '<';

return $qb->compare('e.guid', $operator, $show_guid, ELGG_VALUE_INTEGER);
return $qb->compare("{$main_alias}.guid", $operator, $show_guid, ELGG_VALUE_INTEGER);
},
],
]);
Expand Down
17 changes: 9 additions & 8 deletions views/default/page/elements/comments_block.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,26 @@
// If owner is defined, view only the comments that have
// been posted on objects owned by that user
if ($owner_guid) {
$options['wheres'][] = function(\Elgg\Database\QueryBuilder $qb) use ($owner_guid) {
$qb->joinEntitiesTable('e', 'container_guid', 'inner', 'ce');
return $qb->compare('ce.owner_guid', '=', $owner_guid, ELGG_VALUE_INTEGER);
$options['wheres'][] = function(\Elgg\Database\QueryBuilder $qb, $main_alias) use ($owner_guid) {
$qb->joinEntitiesTable($main_alias, 'container_guid', 'inner', 'ce');
return $qb->compare('ce.owner_guid', '=', $owner_guid, ELGG_VALUE_GUID);
};
}

// If container is defined, view only the comments that have
// been posted on objects placed inside that container
if ($container_guid) {
$options['wheres'][] = function(\Elgg\Database\QueryBuilder $qb) use ($container_guid) {
$qb->joinEntitiesTable('e', 'container_guid', 'inner', 'ce');
return $qb->compare('ce.container_guid', '=', $container_guid, ELGG_VALUE_INTEGER);
$options['wheres'][] = function(\Elgg\Database\QueryBuilder $qb, $main_alias) use ($container_guid) {
$qb->joinEntitiesTable($main_alias, 'container_guid', 'inner', 'ce');
return $qb->compare('ce.container_guid', '=', $container_guid, ELGG_VALUE_GUID);
};
}

// If subtypes are defined, view only the comments that have been
// posted on objects that belong to any of those subtypes
if ($subtypes) {
$options['wheres'][] = function(\Elgg\Database\QueryBuilder $qb) use ($subtypes) {
$qb->joinEntitiesTable('e', 'container_guid', 'inner', 'ce');
$options['wheres'][] = function(\Elgg\Database\QueryBuilder $qb, $main_alias) use ($subtypes) {
$qb->joinEntitiesTable($main_alias, 'container_guid', 'inner', 'ce');
return $qb->compare('ce.subtype', 'IN', $subtypes, ELGG_VALUE_STRING);
};
}
Expand All @@ -60,6 +60,7 @@
'pagination' => false,
'full_view' => false,
'list_class' => 'elgg-latest-comments',
'item_view' => 'object/comment/sidebar',
]);

echo elgg_view_module('aside', elgg_echo('generic_comments:latest'), $body);
2 changes: 1 addition & 1 deletion views/default/river/elements/responses.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

echo elgg_view_entity_list($comments, [
'list_class' => 'elgg-river-comments',
'show_excerpt' => true,
'full_view' => false,
'register_rss_link' => false,
'show_responses' => false,
]);
Expand Down

0 comments on commit ded1060

Please sign in to comment.