summaryrefslogtreecommitdiffstats
path: root/lib/private/Comments/Manager.php
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2022-01-17 11:56:24 +0100
committerVitor Mattos <vitor@php.rio>2022-01-21 08:39:39 -0300
commit189f9f96ce8a93e228acc5821099d8e870576292 (patch)
treef3b0c689e2005b135463795b584825f66af13a8c /lib/private/Comments/Manager.php
parentf071b4dfbbd5fccae9b7b07b9a13ed71ddc91ce4 (diff)
downloadnextcloud-server-189f9f96ce8a93e228acc5821099d8e870576292.tar.gz
nextcloud-server-189f9f96ce8a93e228acc5821099d8e870576292.zip
Limit the summary and sort it afterwards
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/private/Comments/Manager.php')
-rw-r--r--lib/private/Comments/Manager.php21
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php
index 410fcf26f4d..95fb7f24e53 100644
--- a/lib/private/Comments/Manager.php
+++ b/lib/private/Comments/Manager.php
@@ -104,7 +104,18 @@ class Manager implements ICommentsManager {
$data['children_count'] = (int)$data['children_count'];
$data['reference_id'] = $data['reference_id'] ?? null;
if ($this->supportReactions()) {
- $data['reactions'] = json_decode($data['reactions'], true);
+ $list = json_decode($data['reactions'], true);
+ // Ordering does not work on the database with group concat and Oracle,
+ // So we simply sort on the output.
+ if (is_array($list)) {
+ uasort($list, static function($a, $b) {
+ if ($a === $b) {
+ return 0;
+ }
+ return ($a > $b) ? -1 : 1;
+ });
+ }
+ $data['reactions'] = $list;
}
return $data;
}
@@ -1033,10 +1044,8 @@ class Manager implements ICommentsManager {
while ($data = $result->fetch()) {
$commentIds[] = $data['message_id'];
}
- $comments = [];
- $comments = $this->getCommentsById($commentIds);
- return $comments;
+ return $this->getCommentsById($commentIds);
}
/**
@@ -1217,14 +1226,14 @@ class Manager implements ICommentsManager {
->where($totalQuery->expr()->eq('r.parent_id', $qb->createNamedParameter($parentId)))
->groupBy('r.reaction')
->orderBy('total', 'DESC')
- ->setMaxResults(200);
+ ->setMaxResults(20);
$jsonQuery = $this->dbConn->getQueryBuilder();
$jsonQuery
->selectAlias(
$jsonQuery->func()->concat(
$jsonQuery->expr()->literal('{'),
- $jsonQuery->func()->groupConcat('colonseparatedvalue', ',', $jsonQuery->getColumnName('total') . ' DESC'),
+ $jsonQuery->func()->groupConcat('colonseparatedvalue', ','),
$jsonQuery->expr()->literal('}')
),
'json'