mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Limit the summary and sort it afterwards
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
f071b4dfbb
commit
189f9f96ce
2 changed files with 44 additions and 10 deletions
|
|
@ -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'
|
||||
|
|
|
|||
|
|
@ -1175,7 +1175,7 @@ class ManagerTest extends TestCase {
|
|||
/**
|
||||
* @dataProvider providerTestReactionsSummarizeOrdered
|
||||
*/
|
||||
public function testReactionsSummarizeOrdered(array $comments, $expected) {
|
||||
public function testReactionsSummarizeOrdered(array $comments, array $expected, bool $isFullMatch) {
|
||||
$this->skipIfNotSupport4ByteUTF();
|
||||
$manager = $this->getManager();
|
||||
|
||||
|
|
@ -1192,7 +1192,13 @@ class ManagerTest extends TestCase {
|
|||
}
|
||||
}
|
||||
$actual = $manager->get($comment->getParentId());
|
||||
$this->assertSame($expected, $actual->getReactions());
|
||||
|
||||
if ($isFullMatch) {
|
||||
$this->assertSame($expected, $actual->getReactions());
|
||||
} else {
|
||||
$subResult = array_slice($actual->getReactions(), 0, count($expected));
|
||||
$this->assertSame($expected, $subResult);
|
||||
}
|
||||
}
|
||||
|
||||
public function providerTestReactionsSummarizeOrdered(): array {
|
||||
|
|
@ -1203,11 +1209,31 @@ class ManagerTest extends TestCase {
|
|||
['👍', 'alice', 'reaction', 'message'],
|
||||
],
|
||||
['👍' => 1],
|
||||
true,
|
||||
],
|
||||
[
|
||||
[
|
||||
['message', 'alice', 'comment', null],
|
||||
['👎', 'John', 'reaction', 'message'],
|
||||
['💼', 'Luke', 'reaction', 'message'],
|
||||
['📋', 'Luke', 'reaction', 'message'],
|
||||
['🚀', 'Luke', 'reaction', 'message'],
|
||||
['🖤', 'Luke', 'reaction', 'message'],
|
||||
['😜', 'Luke', 'reaction', 'message'],
|
||||
['🌖', 'Luke', 'reaction', 'message'],
|
||||
['💖', 'Luke', 'reaction', 'message'],
|
||||
['📥', 'Luke', 'reaction', 'message'],
|
||||
['🐉', 'Luke', 'reaction', 'message'],
|
||||
['☕', 'Luke', 'reaction', 'message'],
|
||||
['🐄', 'Luke', 'reaction', 'message'],
|
||||
['🐕', 'Luke', 'reaction', 'message'],
|
||||
['🐈', 'Luke', 'reaction', 'message'],
|
||||
['🛂', 'Luke', 'reaction', 'message'],
|
||||
['🕸', 'Luke', 'reaction', 'message'],
|
||||
['🏰', 'Luke', 'reaction', 'message'],
|
||||
['⚙️', 'Luke', 'reaction', 'message'],
|
||||
['🚨', 'Luke', 'reaction', 'message'],
|
||||
['👥', 'Luke', 'reaction', 'message'],
|
||||
['👍', 'Paul', 'reaction', 'message'],
|
||||
['👍', 'Peter', 'reaction', 'message'],
|
||||
['💜', 'Matthew', 'reaction', 'message'],
|
||||
|
|
@ -1215,11 +1241,10 @@ class ManagerTest extends TestCase {
|
|||
['💜', 'Luke', 'reaction', 'message'],
|
||||
],
|
||||
[
|
||||
|
||||
'💜' => 3,
|
||||
'👍' => 2,
|
||||
'👎' => 1,
|
||||
],
|
||||
false,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue