HomePhabricator
Diffusion Comm 1351de7e31f5

[keyserver] Force sorting of inner fetchMessageInfos query on MariaDB

Description

[keyserver] Force sorting of inner fetchMessageInfos query on MariaDB

Summary:
After switching to MariaDB, I saw an issue where fetchMessageInfos was returning the oldest messages rather than the newest ones.

It was happening because nested queries in MariaDB 10.7 seem to drop the order of the rows. I first tried simply adding an additional ORDER BY clause to the outer query, but found that didn't work because the SQL quirky counting logic we use gets processed before the ORDER BY. (Which is in fact the reason for the nested query.)

I did some Googling and found this. It turns out adding any LIMIT will force MariaDB to preserve the order.

Depends on D4499

Test Plan: I made sure fetchMessageInfos was returning results in the correct order by calling fetchMostRecentMessages from the client on a thread with a lot of messages. I then verified that the results were indeed the most recent messages

Reviewers: jonringer-comm, atul, palys-swm

Reviewed By: palys-swm

Subscribers: Adrian, yayabosh

Differential Revision: https://phab.comm.dev/D4500

Details

Provenance
ashoatAuthored on Jul 11 2022, 3:20 PM
Reviewer
tomek
Differential Revision
D4500: [keyserver] Force sorting of inner fetchMessageInfos query on MariaDB
Parents
rCOMMca79cdc275f4: [Chore] Lint nix dev shell
Branches
Unknown
Tags
Unknown