Skip to content

Commit

Permalink
Merge pull request #10357 from nextcloud/backport/10176/stable3.7
Browse files Browse the repository at this point in the history
[stable3.7] fix(threading): Handle threads with duplicate send times
  • Loading branch information
st3iny authored Nov 13, 2024
2 parents f3ba9fe + 71e88d3 commit 8c777f3
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions lib/Db/MessageMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,13 @@ public function findIdsByQuery(Mailbox $mailbox, SearchQuery $query, string $sor
$selfJoin = $select->expr()->andX(
$select->expr()->eq('m.mailbox_id', 'm2.mailbox_id', IQueryBuilder::PARAM_INT),
$select->expr()->eq('m.thread_root_id', 'm2.thread_root_id', IQueryBuilder::PARAM_INT),
$select->expr()->lt('m.sent_at', 'm2.sent_at', IQueryBuilder::PARAM_INT)
$select->expr()->orX(
$select->expr()->lt('m.sent_at', 'm2.sent_at', IQueryBuilder::PARAM_INT),
$select->expr()->andX(
$select->expr()->eq('m.sent_at', 'm2.sent_at', IQueryBuilder::PARAM_INT),
$select->expr()->lt('m.message_id', 'm2.message_id', IQueryBuilder::PARAM_STR),
),
),
);

$select->from($this->getTableName(), 'm')
Expand Down Expand Up @@ -1000,7 +1006,13 @@ public function findIdsGloballyByQuery(IUser $user, SearchQuery $query, ?int $li
$selfJoin = $select->expr()->andX(
$select->expr()->eq('m.mailbox_id', 'm2.mailbox_id', IQueryBuilder::PARAM_INT),
$select->expr()->eq('m.thread_root_id', 'm2.thread_root_id', IQueryBuilder::PARAM_INT),
$select->expr()->lt('m.sent_at', 'm2.sent_at', IQueryBuilder::PARAM_INT)
$select->expr()->orX(
$select->expr()->lt('m.sent_at', 'm2.sent_at', IQueryBuilder::PARAM_INT),
$select->expr()->andX(
$select->expr()->eq('m.sent_at', 'm2.sent_at', IQueryBuilder::PARAM_INT),
$select->expr()->lt('m.message_id', 'm2.message_id', IQueryBuilder::PARAM_STR),
),
),
);

$select->from($this->getTableName(), 'm')
Expand Down Expand Up @@ -1357,9 +1369,15 @@ public function findNewIds(Mailbox $mailbox, array $ids, ?int $lastMessageTimest
$selfJoin = $select->expr()->andX(
$select->expr()->eq('m.mailbox_id', 'm2.mailbox_id', IQueryBuilder::PARAM_INT),
$select->expr()->eq('m.thread_root_id', 'm2.thread_root_id', IQueryBuilder::PARAM_INT),
$sortOrder === IMailSearch::ORDER_NEWEST_FIRST ?
$select->expr()->lt('m.sent_at', 'm2.sent_at', IQueryBuilder::PARAM_INT) :
$select->expr()->gt('m.sent_at', 'm2.sent_at', IQueryBuilder::PARAM_INT)
$select->expr()->orX(
$sortOrder === IMailSearch::ORDER_NEWEST_FIRST ?
$select->expr()->lt('m.sent_at', 'm2.sent_at', IQueryBuilder::PARAM_INT) :
$select->expr()->gt('m.sent_at', 'm2.sent_at', IQueryBuilder::PARAM_INT),
$select->expr()->andX(
$select->expr()->eq('m.sent_at', 'm2.sent_at', IQueryBuilder::PARAM_INT),
$select->expr()->lt('m.message_id', 'm2.message_id', IQueryBuilder::PARAM_STR),
),
),
);
$wheres = [$select->expr()->eq('m.mailbox_id', $select->createNamedParameter($mailbox->getId(), IQueryBuilder::PARAM_INT)),
$select->expr()->andX($subSelect->expr()->notIn('m.id', $select->createParameter('ids'), IQueryBuilder::PARAM_INT_ARRAY)),
Expand Down

0 comments on commit 8c777f3

Please sign in to comment.