Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] mail: avoid costly queries on messages
The combined domain for moderated messages used to trigger a complex database query with two OR conditions on the mail_message table. Unfortunately PostgreSQL seems to be unable to optimize this with indexes, nor to detect that one of the conditions is void (included `AND FALSE`). On large mail_message tables, this significantly slows down calls to message_fetch, e.g. 6s instead of ~70ms, while returning the same results. As a workaround, move the logic for generating the moderation domain to the server side, where it can be: - optimized out when the user is not a moderator - split into 2 distinct DB queries in order to avoid the pathological case After this change, calls to message_fetch with and without messages to moderate execute in respectively ~50ms and ~150ms, instead of 6s, in a test database with 25 million messages. The modified message_fetch signature is backwards-compatible.
- Loading branch information